An Armstrong number (AN) of three digits is an integer such that the sum of the cubes of its digits equals the number itself. For example, 407 is an Ar

Question 2 Armstrong number (3 marks functional 2 style) An Armstrong number (AN) of three digits is an integer such that the sum of the cubes of its digits equals the number itself. For example, 407 is an Armstrong number since 43+03+ 73-407 Write a program called isArmstrong that receives an integer in the range 100-999. The program prints 1 if the number is an AN, otherwise it prints O. Hint: you can calculate the least significant digit of an integer x by calculating x%10 (x mod 10). You can remove the least significant digit from an integer x by dividing it by 10 Write the equivalent script isArmstrong.m in Matlab Challenges (not for marks): 1) Make isArmstrong a function that returns O or 1 rather than printing the result. Write a main program called AN.c that asks the user for a number in the range 100-999 and prints a line saying if the number is an Amstrong number or not. The main program will continue to ask for another number and print the result until the users types a number less than 100 then it exits. 2) Use that function in another main program that finds and prints the four Armstrong numbers in the 100-900 range

An Armstrong number (AN) of three digits is an integer such that the sum of the cubes of its digits equals the number itself. For example, 407 is an Armstrong number since 4^3 + 0^3 + 7^3 = 407. Write a program called isArmstrong that receives an integer in the range 100-999. The program prints 1 if the number is an AN, otherwise it prints 0. You can remove the least significant digit from an integer x by dividing it by 10. Write the equivalent script isArmstrong.m in Matlab. Challenges (not for marks): Make isArmstrong a function that returns 0 or 1 rather than printing the result. Write a main program called AN.c that asks the user for a number in the range 100-999 and prints a line saying if the number is an Amstrong number or not. The main program will continue to ask for another number and print the result until the users types a number less than 100 then it exits. Use that function in another main program that finds and prints the four Armstrong numbers in the 100-900 range.

Expert Answer

 

Solution:

isArmstrong.c

#include<stdio.h>

int main()

{

int num;

// Enter number

printf(“Enter the number in the range 100-999: “);

scanf(“%d”,&num);

int val=num;

int arm=0;

do

{

// Take least significant digit and add by cubing it

arm=arm+((num%10)*(num%10)*(num%10));

 

// Divide the number by 10

num=num/10;

}while(num!=0);

// If the number equals arm

if(val==arm)

// Number is armstrong

printf(“1”);

else

// Number is not armstrong

printf(“0”);

getchar();

getchar();

}

Output:

Enter the number in the range 100-999: 1

1

isArmstrong.m

num=input(‘Enter the number in the range 100-999: ‘);

% Convert number to string

num_str=num2str(num);

tot=0;

for i=1:length(num_str)

% convert each character to number

v=str2num(num_str(i));

% Find the cube

tot=tot+v*v*v;

end

% Check number is armstrong

if(tot==num)

disp(‘1’)

else

disp(‘0’)

end

Output:

Enter the number in the range 100-999: 407

1

Challenges:

1)

AN.c

#include<stdio.h>

int isArmstrong(int num)

{

int val=num;

int arm=0;

do

{

// Take least significant digit and add by cubing it

arm=arm+((num%10)*(num%10)*(num%10));

 

// Divide the number by 10

num=num/10;

}while(num!=0);

// If the number equals arm

if(val==arm)

// Number is armstrong

return 1;

else

// Number is not armstrong

return 0;

}

int main()

{

int num;

while(true)

{

// Enter number

printf(“Enter the number in the range 100-999: “);

scanf(“%d”,&num);

if(num<100)

break;

if(isArmstrong(num)==1)

// Number is armstrong

printf(“1n”);

else

// Number is not armstrong

printf(“0n”);

};

getchar();

getchar();

}

Output:

Enter the number in the range 100-999: 407

1

Enter the number in the range 100-999: 253

0

Enter the number in the range 100-999: 98

2)

#include<stdio.h>

int isArmstrong(int num)

{

int val=num;

int arm=0;

do

{

// Take least significant digit and add by cubing it

arm=arm+((num%10)*(num%10)*(num%10));

 

// Divide the number by 10

num=num/10;

}while(num!=0);

// If the number equals arm

if(val==arm)

// Number is armstrong

return 1;

else

// Number is not armstrong

return 0;

}

int main()

{

int num;

num=100;

int i=0;

while(i<5)

{

if(isArmstrong(num)==1)

{

// Number is armstrong

printf(“%dn”,num);;

i++;

}

num++;

 

};

getchar();

getchar();

}

Output:

153

370

371

407

Buy Essay
Calculate your paper price
Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

24/7 Customer Support

Our agents are ready to help you around the clock. Please feel free to reach out and enquire about anything.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

HOW OUR ONLINE ESSAY WRITING SERVICE WORKS

Let us write that nagging essay.

STEP 1

Submit Your Essay/Homework Instructions

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.

STEP 2

Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.

STEP 3

Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.

STEP 4

Receive your Paper

After Editing, your paper will be sent to you via email.

× How can I help you?