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); }
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.
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.Originally Posted by Babkockdood
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Just decrement by 5.
How about this?
Code:for ( x = 100; x > 1; x--, x--, x--, x--, x--) printf("\n%d\n", x);
I copied it from the last program in which I passed a parameter, which would have been pre-1989 I guess. - esbo
Code:X-=5
Oh for God's sakes I think the OP got it already.
1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
3. Get rid of conio.h and other antiquated DOS crap headers.
4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.