Assigment:22: Step 1 Step 2 Step 3 Step 4
Assigment:22: Step 1 Step 2 Step 3 Step 4
QUESTION:
Write a C program to check whether a given number is Armstrong number or not .
ALGORITHM:
STEP 1 : Start.
STEP 2: Declare n, number, r, result.
STEP 3: Get the required positive number and store in n.
STEP 4: Use while loop until original number is not zero.
r= number %10
result =result+ (r*r*r)
number =number /10
STEP 5: Check if result and n are equal
STEP 6: Print the appropriate output
STEP 7: Stop
FLOWCHART:
Start
CREATED BY PANKAJ
Declare variable:n,num,r,result=0
Input: n
False
while(num!=0)
True
Calculate & initialize
r=num%10
result=result+(r*r*r)
Number=num%10
FALSE True
if(result==n)
Print:“%d is an
Armstrong number”,n
Stop
PROGRAM:
CREATED BY PANKAJ
#include<stdio.h>
#include<conio.h>
void main()
{
int n,num, r, result=0;
clrscr();
printf("Enter a positive integer: ");
scanf("%d", &n);
num=n;
while(num!=0)
{
r=num %10;
result=result+(r*r*r);
number =num / 10;
}
if(result==n)
printf("%d is an Armstrong number ", n);
else
printf("%d is not an Armstrong number", n);
getch();
}
INPUT/OUTPUT:
Enter a positive integer:153
153 is an Armstrong number
CREATED BY PANKAJ