# Thread: simple arithmetic calculations

1. ## simple arithmetic calculations

I just wanted to double check some calculations..
Code:
5 + 3	                              8
5.6 + 8	                             13.6
5.3 – 8.7	                     -3.4
10 / 3	                               3
17 * 2	                               3.4
10 / 3.0	                       3.0
10.0 / 3	                       3.0
10.0 / 3.0	                      3.0
My answers are on the right...Is this what the program would return?

2. No.

Why don't you create a program to do it, and see for yourself?

3. i keep getting different results... would it matter if the variables were defined as int or double, etc? The problem does not specify??

i got 8, 13, -3, 3 for the first 4...using int... is that correct?

4. Post your code. Is the code you are running giving expected results or unexpected results? If unexpected, post what result you found was unexpected, and what code produced it.

5. i guess u are returing int instead of float/double from the fucntion.

you function prototype should look soemthing like this. lets say u function ane us calc
Code:
double calc(double);
ssharish2005

6. i guess u are returing int instead of float/double from the fucntion.

you function prototype should look something like this. lets say u function ane us calc
Code:
double calc(double);
ssharish2005

7. Code:
#include <stdio.h>

#define FOO(expr,guess) "%s = %g (%.1f)\n", #expr, expr, guess
#define BAR(expr,guess) "%s = %d (%d)\n", #expr, expr, guess
#define BAZ(expr,guess) "%s = %d (%.1f)\n", #expr, expr, guess

int main(void)
{
printf(BAR(5 + 3, 8));
printf(FOO(5.6 + 8, 13.6));
printf(FOO(5.3 - 8.7, -3.4));
printf(BAR(10 / 3, 3));
printf(BAZ(17 * 2, 3.4));
printf(FOO(10 / 3.0, 3.0));
printf(FOO(10.0 / 3, 3.0));
printf(FOO(10.0 / 3.0, 3.0));
return 0;
}

/* my output
5 + 3 = 8 (8)
5.6 + 8 = 13.6 (13.6)
5.3 - 8.7 = -3.4 (-3.4)
10 / 3 = 3 (3)
17 * 2 = 34 (3.4)
10 / 3.0 = 3.33333 (3.0)
10.0 / 3 = 3.33333 (3.0)
10.0 / 3.0 = 3.33333 (3.0)
*/

8. 10/3 is...? No, it's not 3.

9. Originally Posted by Dweia
10/3 is...? No, it's not 3.
It is 3 if you are doing integer math

Popular pages Recent additions