Please have a look at this program guys..its for displaying the number of odd digits and even digits in a number and the sum of the odd digits and even digits separately. I don't know why is the program not giving the correct output. Like when I input 34567, it should give
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a, even=0, odd=0, sumeven=0, sumodd=0, p;
cout<<"This program displays the number of even & odd digits in a number you enter and displays their sum"<<endl;
cout<<"Enter a number: ";
cin>>a;
while(a>0)
{
p=a%10;
a=a/10;
if(p%2==0)
{
even++;
sumeven+=p;
}
else
{
odd++;
sumodd+=p;
}
}
cout<<"Number of even digits in the number= "<<even<<endl;
cout<<"Sum of even digits in the number= "<<sumeven<<endl;
cout<<"Number of odd digits in the number= "<<odd<<endl;
cout<<"Sum of odd digits in the number= "<<sumodd<<endl;
getch();
}