I think this is the most understandable program for us as we all know what are
even and odd numbers so here, we have used two loops one for the Even numbers
and others for odd numbers so if you observe every even number has a difference
of 2 from its subsequent even number like 2,4,6 etc so that's why we have used
increment as n=n+2 and same for odd 1,3,5,etc.. and we have initialised odd
numbers from 1 as it is the first odd number and same for even numbers and
condition as n<=50 because we have to only print till 50.
Program
#include
<stdio.h>
#include
<conio.h>
void main()
{
int
n=1,p=2;
printf("Odd numbers are
:\n");
for (n=1;n<=50;n=n+2)
{
printf("%d\t",n);
}
printf("\nEven numbers are :\n");
for (p=2;p<=50;p=p+2)
{
printf("%d\t",p);
}
}
Output:
Post a Comment