choice program to- 1)Reverse 2)Sum of odd digits 3)Sum of even digits 4)Sum of digits 5)Sum of digits at odd places 6)Sum of digits at even places

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
char y;
unsigned long int c,a,cnt=0,rev=0;
do{
cout<<“Enter the number :”;
cin>>c;
cout<<“\nEnter your choice:\n1)Reverse\n2)Sum of odd digits\n3)Sum of even digits\n”;
cout<<“4)Sum of digits\n5)Sum of digits at odd places\n6)Sum of digits at even places\n”;
cin>>a;
switch(a)
{
case 1:{
while(c!=0)
{
rev=(rev*10)+(c%10);
c=c/10;
}
cout<<“\nReverse of digit is “<<rev;
break;
}
case 2:{
unsigned long int b,sum=0;
while(c!=0)
{
b=c%10;
c=c/10;
if(b%2!=0)
{
sum=sum+b;
}
}
cout<<“\nSum of odd digits is “<<sum;
break;
}
case 3:{
unsigned long int b,sum=0;
while(c!=0)
{
b=c%10;
c=c/10;
if(b%2==0)
{
sum=sum+b;
}
}
cout<<“\nSum of even digits is “<<sum;
break;
}
case 4:{
unsigned long int sum=0;
while(c!=0)
{
sum=sum+(c%10);
c=c/10;
}
cout<<“\nSum of digits is “<<sum;
break;
}
case 5:{
unsigned long int sum=0,b;
while(c!=0)
{
rev=(rev*10)+(c%10);
c=c/10;
}
while(rev!=0)
{
b=rev%10;
rev=rev/10;
cnt++;
if(cnt%2!=0)
{
sum=sum+b;
}
}
cout<<“\nSum of digits at odd places is “<<sum;
break;
}
case 6:{
unsigned long int sum=0,b;
while(c!=0)
{
rev=(rev*10)+(c%10);
c=c/10;
}
while(rev!=0)
{
b=rev%10;
rev=rev/10;
cnt++;
if(cnt%2==0)
{
sum=sum+b;
}
}
cout<<“\nSum of digits at even places is “<<sum;
break;
}
}
cout<<“\nTo do again enter (y/Y) :”;
cin>>y;
}while(y==’y’||y==’Y’);
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s