Write a program to print all even numbers between 0 and an integer number entered by
the user using:
a. For loop
b. While loop
c. Do while loop
#include <stdio.h>
int main()
{
int number;
printf("Enter number: ");
scanf("%d", &number);
int i;
for(i = 0; i < number; i+=2)
printf("%d ", i);
printf("\n");
i = 0;
while(i < number)
{
printf("%d ", i);
i +=2;
}
printf("\n");
i = 0;
do
{
printf("%d ", i);
i+=2;
}while(i < number);
return 0;
}
Comments
Leave a comment