Basic Data Types

  • + 56 comments

    Instead, why not find a working solution for both. Below are solutions that work for this example:

    scanf / printf (C):

    #include <iostream>
    int main() {
        int a; long b; char c; float d; double e;
        
        scanf("%i %li %c %f %lf",&a,&b,&c,&d,&e);
        printf("%i\n%li\n%c\n%.03f\n%.09lf\n",a,b,c,d,e);
        
        return 0;
    }
    

    cin / cout (C++):

    #include <iostream>
    using std::cin;
    using std::cout;
    using std::endl;
    using std::fixed;
    
    int main() {
        int a; long b; char c; float d; double e;
        cin>>a>>b>>c>>d>>e;
        cout<<a<<endl;
        cout<<b<<endl;
        cout<<c<<endl;
        cout.precision(3);
        cout<<fixed<<d<<endl;
        cout.precision(9);
        cout<<fixed<<e<<endl;
        return 0;
    }