The C program is given below is a program that will print the even numbers between 1 to 50. I have used a do-while loop to make that possible. First of all I have taken an integer type variable i where I have kept 2. Then I have started the do-while loop. I have told the compiler to print the value from the variable i and just at the next line I have told to add 2 with the existing value if i. The loop process will continue till the value of i<=50.
#include<stdio.h>
void main() {
int i=2;
do {
printf("%d, ",i);
i=i+2;
}
while(i<=50);
}
No comments:
Post a Comment