How to sum mixed numeric types explicitly in C

1 Answer

0 votes
#include <stdio.h>

int main() {
    int a = 5;
    float b = 3.2f;
    double c = 10.75;

    double sum = a + b + c;   // all promoted to double

    printf("Sum = %.2f\n", sum);

    return 0;
}



/* 
run:

Sum = 18.95

*/

 



answered May 1 by avibootz

Related questions

1 answer 244 views
1 answer 263 views
1 answer 258 views
258 views asked Nov 22, 2020 by avibootz
1 answer 277 views
277 views asked Sep 28, 2020 by avibootz
5 answers 587 views
1 answer 380 views
...