Computer Science, asked by akbadoh7, 11 months ago

Write a program which prints the sum of the cubes of the digits of
a number.

Answers

Answered by pranav4457
0

Answer:

it is located in computer science

Answered by StaceeLichtenstein
1

#include <iostream> // header file

using namespace std; // namespace

int main() // main method

{

   int n,s=0; // variable declaration

   cout<<"Enter the number:";

   cin>>n; // Read the number by user

   while(n>0) // iterating the while loop

   {

       

       int rem=n%10; // calculating the reminder

       s=s+rem*rem*rem; //Sum of cubes of //number

       n=n/10; // gives quotient

   }

   

   cout<<"Sum of cubes of number :"<<s; //  //   //display

   return 0;

}

Output:

Enter the number:123

Sum of cubes of number :36

Explanation:

Following is the description of program

  • Declared a variable "n" and "s" of "int" type.
  • Initialized "s" to 0.
  • Read the input by user in "n" variable.
  • Iterating the loop greater then 0.
  • In this while loop calculate the reminder in the "rem" variable by using n%10 operation ;
  • After that calculating Sum of cubes of number in the variable "s".
  • Perform operation n=n/10 it gives the quotient .
  • Finally display the variable "s".

Learn More:

https://brainly.in/question/15438777

Similar questions