Code Explanation:
- It declares variables:
number
(input number),num
(temporary variable to store the number),rem
(remainder), andresult
(to store the result of calculations). - It takes input for a number.
- It stores the input number in the
num
variable for later reference. - 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. - After the loop, it checks if the calculated result (
result
) matches the original number (number
). - 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;
}
0 Comments
if you have any doubt, plz let me know