C Programming counting program that counts from 1 to 100.?
I need the steps for C Programming a counting program that counts from 1 to 100
3 Answers
- darrenforster99Lv 68 years ago
int counter ( int count=1)
{
if ( count < 101 )
{
/*do something*/
return ( counter ( count+1 ) ) ;
}
else
return ( 0 ) ;
}
int main ()
{
return ( counter () ) ;
}
There you go counts from 1 to 100 recursively, of course you may want it to do something with the count variable like output to screen or else you've just wasted over 100 CPU cycles ;)
If you did want it to just count to 100 without displaying anything you could change counter to the following
int counter ( int count = 0 )
{
return ( ( count < 101 ? counter ( count+1 ) : 0 ) ) ;
}
}
- 4 years ago
i could attempt this: for (i=a million; i<a hundred;) { printf("%d ", i); i=i*2; } provides: a million 2 4 8 sixteen 32 sixty 4 (as a results of fact 128 > a hundred) Or are you desirous to maintain doubling a hundred circumstances? if so you desire an added variable: int j=a million; for (i=a million; i<a hundred;) { printf("%d ", j); j=j*2; i++; }
- 8 years ago
include<stdio.h>
int main()
{
int x=1; // Dont forget to declare variables
while (x<101){ //while x is less than 101
printf("%d\n",x);
x++; // update x so the condition can met eventually
}
getchar();
}
}