Ad Code

NEW POST

6/recent/ticker-posts

Armstrong was one of the greatest scientist | SRM ELAB DLD

c program

Code Explanation:

  1. It declares variables: number (input number), num (temporary variable to store the number), rem (remainder), and result (to store the result of calculations).
  2. It takes input for a number.
  3. It stores the input number in the num variable for later reference.
  4. Using a while loop, it extracts each digit from the number one by one (rem = num % 10) and calculates the sum of cubes of these digits (result += rem * rem * rem). It removes the last digit from the number (num /= 10) in each iteration until the number becomes 0.
  5. After the loop, it checks if the calculated result (result) matches the original number (number).
  6. If the result matches the original number, it outputs "Part of Memorable Coin," indicating that the number is part of the sequence. Otherwise, it outputs "Not a Part of Memorable Coin."

In summary, this program checks whether a given number satisfies a specific property related to the "Memorable Coin" sequence, which involves summing the cubes of its individual digits. If the calculated sum matches the original number, it's considered part of the sequence.

C++ Code:

#include <iostream>

using namespace std;

int main()

{

 int number,num,rem,result=0;

 cin>>number;

 num=number;

 while(num!=0) {

 rem = num%10;

 result+=rem*rem*rem;

 num/=10;

 }

 if(result==number)

 cout<<"Part of Memorable Coin";

 else

 cout<<"Not a Part of Memorable Coin";

 return 0;

}

Post a Comment

0 Comments