Print all even numbers between 1 to 100. with using while loop with C
#include <stdio.h>
int main()
{
int i, n;
printf("Enter last number: ");
scanf("%d", &n);
printf("Even numbers from 1 to %d are: ", n);
for (i = 1; i <= n; i++)
{
if (i % 2 == 0)
{
printf("%d ", i);
}
}
return 0;
}
Output:-
Enter last number: 10
Even numbers from 1 to 10 are: 2 4 6 8 10
0 Comments