Pages

Friday, July 19, 2013

[H]. (m) If a five-digit number is input through the keyboard, write a program to print a new number by adding one to each of its digits. For example if the number that is input is 12391 then the output should be displayed as 23402.

void main()
{
int a, b, c, d, e;
long num;
clrscr();
printf("Enter Five Digit Number : ");
scanf("%ld",&num);
e=num%10;
num=num/10;
d=num%10;
num=num/10;
c=num%10;
num=num/10;
b=num%10;
num=num/10;
a=num%10;
a=a+1;
b=b+1;
c=c+1;
d=d+1;
e=e+1;
a=a%10;
b=b%10;
c=c%10;
d=d%10;
e=e%10;
printf("New Number = %d%d%d%d%d",a,b,c,d,e);
getch();
}

No comments:

Post a Comment