SOURCE CODE OUTPUT
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int n,osum=0,esum=0,temp;
cout<<"Enter the number ";
cin>>n;
while(n>0)
{
temp=n%10;
if(temp%2==0)
esum+=temp;
else
osum+=temp;
n/=10;
}
cout<<"Sum of odd digits = "<<osum<<endl;
cout<<"Sum of even digits = "<<esum;
return 0;
}
#include<math.h>
using namespace std;
int main()
{
int n,osum=0,esum=0,temp;
cout<<"Enter the number ";
cin>>n;
while(n>0)
{
temp=n%10;
if(temp%2==0)
esum+=temp;
else
osum+=temp;
n/=10;
}
cout<<"Sum of odd digits = "<<osum<<endl;
cout<<"Sum of even digits = "<<esum;
return 0;
}
Any questions regarding to program please write in comments.
No comments:
Post a Comment