Input 10 number check all are even or not using for loop in C
for Loop - Question 7
In this question, we will see how to input 10 numbers and check whether all the entered numbers are even numbers only or not in C programming using for loop. To know more about for loop click on the for loop lesson.
Q7) Write a program in C to input 10 numbers and check whether all the entered numbers are even numbers only or not using for loop.
Program
#include <stdio.h>
#include <conio.h>
int main()
{
int i,n,ec=0;
printf("Enter 10 numbers\n");
for(i=1; i<=10; i=i+1)
{
scanf("%d",&n);
if(n%2==0)
{
ec=ec+1; // counting the even numbers
}
}
if(ec==10)
{
printf("All numbers are even");
}
else
{
printf("All numbers are not even");
}
return 0;
}
Output
Enter 10 numbers 2 8 6 12 18 36 24 4 48 90 All numbers are even