Monday, 14 March 2016

Hacker Rank Solution Program In C++ For "Basic Data Types "

1.Solution In C++ :- You can use iomanip Header file to make easy solution .below is another solution in c language Check after C++ Solution.and don't forgot to share with friends

Try This Code:- for c++ domain

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

int main()
{
    int integer;
    long long1;//by default int long
    long long long2; //by default int long long
    char character;
    float floatnumber;
    double doublenumber;
    cin>>integer;
    cin>>long1;
    cin>>long2;
    cin>>character;
    cin>>floatnumber;
    cin>>doublenumber;
    cout << setprecision(20) << integer<< endl;
    cout << setprecision(20) << long1<< endl;
    cout << setprecision(20) << long2<< endl;
    cout << setprecision(20) << character<< endl;
    cout << setprecision(20) << floatnumber<< endl;
    cout << setprecision(20) << doublenumber<< endl;
    return 0;

}


Output:-

Hacker Rank Solution Program In C++ For "Basic Data Types "


2.Solution In C :- Try This code with C domain And don't Forgot To Share

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

int main()
{
int a;
long int b;
long long int c;
char d;
float e;
double f;
scanf("%d %ld %lld %c %f %lf",&a,&b,&c,&d,&e,&f);
printf("%d\n%ld\n%lld\n%c\n%f\n%lf",a,b,c,d,e,f);
    return 0;
}

Output:-

programmingwithbasics

2 comments:
Write comments
  1. if we use cout and cin intead of scanf anf printf it is giving error. cam anyone tell me why?

    ReplyDelete
    Replies
    1. Hii AARUSHI
      C is closer to the machine circuit, hardware, etc than C++ is. But at the same time C++ "arguably" allows more direct manipulation of your data.you can use iomanip to solve the problem i if you are good in webtechnology Click Here

      Delete

Recommended Posts × +