(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 23502.

Let Us C by Yashwant Kanetkar

 

Solution By Muhammad Kaleem UIlah



                                                                  Exercise Questions 
[H] Write C programs for the following:

(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 23502.

int main ()

{

    int num,rem1,rem2,rem3,rem4,rem5;

    int dig1,dig2,dig3,dig4,dig5;

    int carry1,carry2,carry3,carry4,carry5;

    printf("\n\t\t Enter Your Favourite 5 Digits =");

    scanf("%d",&num);

    rem1=num/10000;

    num=num%10000;

    rem2=num/1000;

    num=num%1000;

    rem3=num/100;

    num=num%100;

    rem4=num/10;

    num=num%10;

    rem5=num;

 

    rem5=rem5+1;

    dig5=rem5%10;

 

    carry1=rem5/10;

    rem4=rem4+1;

    rem4=rem4+carry1;

    dig4=rem4%10;

 

    carry2=rem4/10;

    rem3=rem3+1;

    rem3=rem3+carry2;

    dig3=rem3%10;

 

    carry3=rem3/10;

    rem2=rem2+1;

    rem2=rem2+carry3;

    dig2=rem2%10;

 

    carry4=rem2/10;

    rem1=rem1+1;

    rem1=rem1+carry4;

 

    printf("%d",rem1);

    printf("%d",dig2);

    printf("%d",dig3);

    printf("%d",dig4);

    printf("%d",dig5);

 

    return 0;

}


Comments

Popular posts from this blog

(k) A cashier has currency notes of denominations 10, 50 and 100. If the amount to be withdrawn is input through the keyboard in hundreds, find the total number of currency notes of each denomination the cashier will have to give to the withdrawer.

(j) In a town, the percentage of men is 52. The percentage of total literacy is 48. If total percentage of literate men is 35 of the total population, write a program to find the total number of illiterate men and women if the population of the town is 80,000.

EXERCISE 01 Complete Solved LET US C by Yashwant Kanetkar