An Armstrong number is a number of n digits that is equal to the sum of each dig
ID: 3750125 • Letter: A
Question
An Armstrong number is a number of n digits that is equal to the sum of each digit raised to the nth power. For example, 153 (which has three decimal digits) equals 131 53 1 33. Write a function to test whether a three-digit number is an Armstrong number and a test program to store all three-digit Armstrong numbers in an array.
Write a program to find the first five numbers that when divided by 2, 3, 4, 5, and 6 leave a remainder of 1, and when divided by 7, have no remainder. (test to confirm it works)
Write a subroutine that rotates the stepper motor shown in Figure 10.8 (in the notes) counterclockwise in full steps and also a subroutine that rotates the motor in half steps, respectively.
Write in C
PA3 Step motor Vcc V, Figure 10.8 Driving a stepper motorExplanation / Answer
Hi,
for the first question "To check whether a given 3 digit number is Armstrong or not ", I have given the c code below. The code will ask the user for input and give the output whether the given number is Armstrong or not.
Second part of the code will print all 3 digit armstrong numbers and print the total number of armstrong number .
#include <stdio.h>
//Test weather a given 3 digit number is armstrong or not
int main()
{
int number_input,temp,sum=0,l;
int store_armstrong[10];
int total_count=0,start=100,end=999;
printf("Enter a 3 digit number to be checked ");
scanf("%d",&number_input);
temp=number_input;
while(temp>0)
{
l=temp%10;
sum=sum+(l*l*l);
temp=temp/10;
}
if (sum==number_input)
{
printf("Yes, given number is armstrong ");
}
else
{
printf("No, given number is not an armstrong number ");
}
//Store all 3 digit armstrong number
for (int i=start;i<end;i++)
{
sum=0;
temp=i;
while(temp>0)
{
l=temp%10;
sum=sum+(l*l*l);
temp=temp/10;
}
if (sum==i)
{
printf("Armstrong number detected = %d ",i);
store_armstrong[total_count]=i;
total_count++;
}
}
printf("Total number of 3 digit armstrong numbers are = %d",total_count);
}
For the question "Write a program to find the first five numbers that when divided by 2, 3, 4, 5, and 6 leave a remainder of 1, and when divided by 7, have no remainder." solution is given below :-
#include <stdio.h>
int main()
{
int start=1,count=0;
for (int i=start;count<5;i++)
{
if(i%2==1 && i%3==1 && i%4==1 && i%5==1 && i%6==1 && i%7==0)
{
printf("valid number is = %d ",i);
count++;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.