Friday, October 16, 2020

HACKERRANK C++ BASIC DATA TYPES


SOLUTION-

Input and Output it's easier to take input using cin and cout or you could still use printf and scanf. Now the tricky part is while trying to print the floating and double values. You need to use setprecision() which is available in the iomanip library. 

 #include <iostream>

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

int main() {
    
    int a;
    long b;
    char c;
    float d;
    double e;
    cin >> a >> b >> c >> d >> e;
    cout<< a << '\n' << b << '\n' << c << '\n';
    cout << std::fixed << std::setprecision(3) << d << '\n';
    cout << std::fixed << std::setprecision(9) << e << '\n';
    
    return 0;
}
#include <iostream>
#include <cstdio>
using namespace std;

int main() {
    // Complete the code.
    int i;
    long l;
    char c;
    float f;
    double d;
    scanf("%d %ld %c %f %lf" , &i, &l, &c, &f, &d);
    printf("%d\n%ld\n%c\n%.3f\n%.9lf\n", i,l,c,f,d);

    return 0;
}

No comments:

Post a Comment

LEETCODE JUNE 2021 DAILY CODING CHALLENGE

 LEETCODE JUNE 2021 DAILY CODING CHALLENGE JUNE 1 JUNE 2 JUNE 3 JUNE 4 JUNE 5 Maximum Performance of a Team LINK You are given two integers ...