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 <iostream>
#include <conio.h>
using namespace std;
int main()
{
int i,n,ec=0;
cout<<"Enter 10 numbers\n";
for(i=1; i<=10; i=i+1)
{
cin>>n;
if(n%2==0)
{
ec=ec+1; // counting the even numbers
}
}
if(ec==10)
{
cout<<"All numbers are even";
}
else
{
cout<<"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