What will be the output of the following C++ code? [code] #include <stdio.h> #include <stdlib.h> int main () {

Nguyên Lê

New member
What will be the output of the following C++ code?
Code:
    #include <stdio.h>    
    #include <stdlib.h>
    int main ()
    {
        char s[] = "365.24 29.53";
        char* p;
        double d1, d2;
        d1 = strtod (s, &p);
        d2 = strtod (p, NULL);
        printf ("%.2f\n", d1/d2);
        return 0;
    }
A. 12
B. 12.37
C. 13
D. 15
 
Answer: b
Explanation: In this program, We are calculating the double value by using the floating point number and we are using the function strtod.
Output:
Code:
$ g++ cinc.cpp
$ a.out
 

Tìm kiếm

Back
Top