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.
Code
void main(){
long int var1,i,vSize=0,rVar=0,vL,vAd=0; // Variable declaration
clrscr();
printf("Enter an Integer: "); /// Getting the input from the user
scanf("%ld",&var1);
vL=var1; /// Counding the input digits
while(vL>0){
vSize++;
vL /=10;
}
vL = var1;
printf("\n Size of Integer is %ld",vSize);
/// Reversing the input digits
for(i=1;i<=vSize;i++){
rVar *= 10;
rVar += vL%10;
vL /=10;
}
printf("\n Reverse Integer is %ld",rVar);
/// Making in original form by adding 1 (One) to each digit
for(i=1;i<=vSize;i++){
vAd *= 10;
vAd += (((rVar%10)+1)%10);
rVar /=10;
}
printf("\n After adding 1 to each Integer is %ld",vAd);
getch();
}
Output of the code

No comments:
Post a Comment