There are several ways the for loop is the most common with you just incrementing by two and printing the numbers that are odd as all odd numbers are two apart, still there are other ways to do loops in C.
The While loop
int i =1; /* this sets the number to 1 */
while ( i <= 49) /* If the number is less than or equal to 49 the loop will continue */
{ /* begining of loop */
printf("%d ",i); /* this prints the number the first is the number 1*/
i+=2; /* Now add 2 to the number */
/*the loop will go back to the start */
} /* end of loop */
the next one is the do while loop not so often used but still a valid loop
int i =1; /* the variable i is initialised to 1*/
do /* Start of loop */
{
printf("%d ",i);
i=i+2; /* This increments by two
or you can use
i+=2; they are the same
*/
} while ( i <= 49)
/* this checks the value if it is less than 49 it goes back to a loop */
Then there is the recursive - this is when you create a function that calls it's self a bit cleverer version
int count_odd(int x); /* predeclaration of function */
int main()
{
int x = 1;
int number;
number =count_odd(x);
printf(
return 0;
}
/* this is the function which returns a value */
int count_odd(int x)
{
/* this sets the limit to 49 so if the value is equal to 49 it doesn't call it's self*/
if (x == 49 )
return 0;
else
{
/* prints the value of x */
printf( "%d " , x);
/* the function now calls on it's self but adds two the value */
return count_odd(x + 2);
}