Back to Home Page

/******************************************************************************
Problem: Write a program to evaluate if a integer number is a Perfect Cube or
number of Armstrong ( Number > 1 ).Your program should include
a loop that lets the user repeat this calculation until the user
says she or he is done.
Note: if abc is perfect cube then abc = a^3 + b^3 + c^3
e.g., 153 = 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153

Course: Objects Structures and Algorithms 1
Tutor : Guillermo Julca
Mercy College

View Output
*******************************************************************************/

//---------------------------------------------------------------------------

#pragma hdrstop
#include <iostream.h>
#include <conio.h>

//---------------------------------------------------------------------------

#pragma argsused
int main(int argc, char* argv[])
{
int number;
char ans;
do
{
do
{
cout<<"Enter a Integer Number greater than 1 : ";
cin>>number;
}while ( number <= 1);
int result;
int Naux;
result = 0;
Naux = number;
int dig;
while (Naux != 0)
{
dig = Naux % 10;
Naux = Naux / 10;
result = result + pow(dig,3);
}// end while (Naux != 0)
if (number == result)
cout<<"The number is PERFECT CUBE !!!"<<endl;
else
cout<<"The number is NOT PERFECT CUBE "<<endl;
cout<< "Continue (Y/N) : ";
cin>> ans;
}while(ans=='Y' || ans=='y');
getchar();

return 0;
}

View Output
//---------------------------------------------------------------------------

Back to Home Page


Copyright  © 2002                                   GJ  GUILLERMO JULCA