বৃহস্পতিবার, ৪ ফেব্রুয়ারি, ২০১৬

check an input integer or double by c++

#include<iostream>
using namespace std;

int main()
{
    double a;
    cout << "Enter the number: ";
    cin >> a;
    int b = (int)a;
    if((a / b) == 1)
        cout << "Integer" << endl;
    else
        cout << "Double" << endl;
    return 0;
}

///ahmed shuvo969



বুধবার, ৩ ফেব্রুয়ারি, ২০১৬

Get the lenght of number/character without using header file by c++

#include<iostream>
using namespace std;

int main()
{
    int i = 0,  degit = 0;
    char string[80];
    cout << "enter the number/character : ";
    cin >> string;
    while((string[i++]) != '\0')
            ++degit;
    cout << "The length of string is : " << degit << endl;

   return 0;
}





///ahmed shuvo969

Get the lenght of number/character by c++

#include<iostream>
#include<string>
using namespace std;

int main()
{
    string n;
    cout << "Enter the number/character : ";
    cin >> n;
    cout <<"The length of this number: "<< n.length() << endl;
    return 0;
}

///ahmed shuvo969

lightOj 1294 - Positive Negative Sign solve by c++

#include <iostream>
using namespace std;

int main(){

    int T;
    cin >> T;
    for(int t = 1; t <= T; t++){
        long long int n,m;
        cin >> n >> m;
        cout << "Case " << t << ": " << (n*m)/2 << endl;
    }
    return 0;
}

///ahmed shuvo969

Convert Decimal to Binary by c++

#include <iostream>
using namespace std;
int main()
{
    long dec,rem,i=1,sum=0;
    cout<<"Enter the decimal to be converted:";
    cin>>dec;
    while(dec>0)
    {
        rem=dec%2;
        sum=sum + (i*rem);
        dec=dec/2;
        i=i*10;
    };
    cout<<"The binary of the given number is:"<<sum<<endl;

    return 0;
}


//ahmed shuvo969

Convert Binary to Decimal by c++

#include<iostream>
#include<math.h>
using namespace std;

int main()
{
    int outcome = 0, i, n;
    cout << "Enter the binary number: ";
    cin >> n;
    for(i = 0; n > 0; i++)
    {
        if(n % 10 == 1)
            outcome += pow(2, i);
        n = n / 10;
    }
    cout << "The decimal number of " << n << " is : " << outcome << endl;
    return 0;
}

//ahemdshuvo969

মঙ্গলবার, ২ ফেব্রুয়ারি, ২০১৬

lightOj-1311 - Unlucky Bird solve by c++

#include<iostream>
#include<iomanip>
using namespace std;

int main()
{
int test;
double v1, v2, v3, a1, a2, t, t1, t2, fly, s;
cin >> test;

for(int i = 1; i <= test; i++)
{
    cin >> v1 >> v2 >> v3 >> a1 >> a2;
    t1 = v1 / a1;
    t2 = v2 / a2;
    t = max(t1, t2);
    fly = v3 * t;
    s = v1 * t1 + 0.5 * -a1 * t1 * t1;
    s += v2 * t2 + 0.5 * -a2 * t2 * t2;
    cout << fixed << setprecision(9) << "Case " << test << ": " << s << " " << fly << endl;
}
    return 0;
}

ahmed shuvo969