How to write a program to count no. of odd and even digits a number contain?
CODE
How
to write a program to count no. of odd and even digits a number contain?
int main()
{
int n,r,ec=0,oc=0;
printf("\n enter the number=");
scanf("%d",&n);
while(n!=0)
{
r=n%10;
if(r%2==0)
ec++;
else
oc++;
n=n/10;
}
printf("\n No. of even
digits:%d",ec);
printf("\n No. of odd
digits:%d",oc);
}
Output:
enter the number= 4567
No.
of even digits:2
No.
of odd digits:2
How to write a program to count no. of odd and even digits a number contain?
Reviewed by Unknown
on
December 16, 2018
Rating:
No comments:
If you have any doubt or query ,comment below: