Saturday, 19 August 2017

11-C Prg-6. Write a program to read a number and print the number of digits and the sum of the digits.

11-C Prg-6. Write a program to read a number and print the number
of digits and the sum of the digits.

Algoithim:
Input
1. n (567)

Output:
1. print the numbers (7, 6, 5)
2. sum of the digits( sum= 5+6+7=18)

Method:
1.start       //int n,sum,r;
2. Read n
3. write n
4. sum=0;
5. //logic

   do                   do
   begin  {
    r=n % 10;     r=n%10;
    write r;                 cout<<"digits="<<r;
    sum=sum+r;               sum=sum+r;
    n=n/10;                  n=n/10;
   end while(n != 0)       } while(n !=0);
6. write sum
7.stop

No comments:

Post a Comment