how do i make my program count by fives or tens
Code:
#include <stdio.h>
main()
{
int x;
for ( x = 100; x > 1; x-- )
printf("\n%d\n", x);
}
Printable View
how do i make my program count by fives or tens
Code:
#include <stdio.h>
main()
{
int x;
for ( x = 100; x > 1; x-- )
printf("\n%d\n", x);
}
Make the change of x in the loop a multiple of five (or ten). Alternately, print x*5 (or x*10).
Your x changes by a factor of five, duh.
Replace x-- with x = x+5. And for tens, use x = x+10.
This suggestion echos the spirit of the earlier posts, but note that if you actually implement it, you will end up with an infinite loop.Quote:
Originally Posted by Babkockdood
Just decrement by 5.
How about this?
Code:for ( x = 100; x > 1; x--, x--, x--, x--, x--)
printf("\n%d\n", x);
Code:X-=5
Oh for God's sakes I think the OP got it already.