Input a number and check whether all digits are even or not using while loop in C
while Loop - Question 12
In this question, we will see how to input a number and check if all digits in the number are even digit or not in C programming using while loop. To know more about while loop click on the while loop lesson.
Q12) Write a program in C to input a number and check if all digits in the number are even digit or not using while loop.
Program
#include <stdio.h>
#include <conio.h>
int main()
{
int n,d,td=0,ed=0;
printf("Enter any number ");
scanf("%d",&n);
while(n>0)
{
d=n%10;
if(d%2==0)
{
ed=ed+1; // counting the even digits
}
td=td+1; // counting the total number of digits
n=n/10;
}
if(td==ed)
{
printf("All digits are even digit");
}
else
{
printf("All digits are not even digit");
}
return 0;
}
Output
Enter any number 6248 All digits are even digit