Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Ratish Patil F-2-41

Experiment No:8 Armstrong


Number of Three Digits
Aim: Write a program to check if the given number is
Armstrong or not.

Theory:
While loop: The while Loop is an entry-controlled loop in C
programming language. This loop can be used to iterate a part of
code while the given condition remains true.

Syntax:
while (test expression)
{
// body consisting of multiple statements
}

Algorithm:
Step-1: Start
Step-2: Declare a function that declares the parameter n
Step-3: Declare variables rem, sum, d, num
Step-4: Initialize sum=0 and d=n
Step-5: Inside while loop, rem=n%10, sum +=rem*rem*rem,
n/=10
Step-6: if sum=d, display the given number is an Armstrong
number else print the given number is not an
Armstrong number
Step-7: Inside the main function, define a calling function arm that takes
an integer value num from the user
Step-8: Stop.
Flowchart:
Program:
#include<stdio.h>
int arm(int n)
{
int rem,sum=0,d,num;
d=n;
while(n>0)
{
rem = n%10;
sum = sum + rem*rem*rem;
n = n/10;
}
if(sum == d )
{
printf("%d is an Armstrong number!",d);
}
else
{ printf("%d is not an Armstrong number!",d);
}
}
int main()
{
int num;
printf("Enter the number: ");
scanf("%d",&num);
arm(num);
return 0;
}
Output:
Conclusion:
An Armstrong Number is defined as the sum of
the nth power of each digit to an n-digit number
that is equal to that number.

You might also like