Question: Write a WinMIPS64 code to determine whether a given number is an Armstrong number. The n -digit numbers equal to sum of n th powers
Write a WinMIPS64 code to determine whether a given number is an Armstrong number. The n-digit numbers equal to sum of nth powers of their digits (a finite sequence), called Armstrong numbers. They first few are given by 1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 1634, 8208, 9474, 54748,.
For example, consider 371, 371 = 33 + 73+ 13 = 27 + 343 + 1 = 371. A sample C code for your assistance is given below:
#include
#include
int main(){
int num,i;
int digit,sum,capture;
sum = 0.0;
capture = 0.0;
printf( "Enter the total number of digits " );
scanf( "%d", &num );
for( i = 0; i < num; i++ ) {
printf( "Enter the %d digit: ", i+1 );
scanf( "%d", &digit );
sum = sum + pow(digit,num);
capture = capture * 10 + digit;
}
printf( "Entered Number: %d ", capture );
printf( "Sum of Product: %d ", sum );
if( capture == sum )
printf( "Armstrong number" );
else
printf( "Not an Armstrong number" );
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
