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 238 views
1 answer 259 views
1 answer 251 views
251 views asked Nov 22, 2020 by avibootz
1 answer 267 views
267 views asked Sep 28, 2020 by avibootz
5 answers 579 views
1 answer 372 views
...