Computer Science, asked by sangitarai7282, 3 months ago

Write a program to accept a number then print the sum of digits and number of digits present in it. (E.g. If the input number is 225,the sum of digits is 9 and number of digits is 3)​

Answers

Answered by ewshedata
0

Answer:

Explanation:

use c++ language

   

   cin>>number;                  //read number

   sum=0,length=0;            //assign sum and length to zero

   for (int i=number;i!=0;){

       sum=sum+i%10;          //sum the digit by digit

       i=i/10;

       length++;                    //how many digits

   }

  //show the result

   cout<<"the sum of digits:"<<sum<<"\n";

   cout<<"number of digits:"<<length<<"\n";

Similar questions