Output

hello everyone can you please help me with my project.
Every time I run this program the average or b in this case is not decreasing.
the output I always get is
100
0
0
0
0
and so on.
It should be
100
90
80
...
please help.

#include<conio.h>
#include<stdio.h>
main()
{
int a=10,b,c=10;
for(c=10; c>=0; c--)

{

b=(c/a)*100;


printf("%d - %d\n", c,b);
}





getch();
return 0;
}

Please use code tags next time ( <> button).

Your variable type is Interger and if you divide it will always return the same type.
So since Integer is unable to store floating point numbers 9/10 will result in 0.

You either have to change the variable types of your a,b,c to float or double or use a cast
when dividing.

1
2
3
4
5
float a=10,b,c=10;

//or

b=( (float)c / (float)a )*100;
Checkout this line
b = (c / a) * 100;

This always produce 0 in your code.
Try to change a to double instead of int.
Topic archived. No new replies allowed.