To check whether the given Number is Armstrong Number or Not by using for loop

 Program:


#include<stdio.h>
#include<conio.h>
void main()
{
    int n, sum=0, m, r;
    clrscr();
    printf("Enter any Number : ");
    scanf("%d", &n);
    m=n;
    while(m>0)
    {
        r=m%10;
        sum=sum+(r*r*r);
        m=m/10;       
    }
    if(n==sum)
        printf("Given Number is Armstrong Number ");
    else
        printf("Given Number is Not Armstrong Number ");
    getch();
}

Output:


Ex-1:
Enter any Number : 153
Given Number is Armstrong Number 

Ex-2:
Enter any Number : 370
Given Number is Armstrong Number 

Ex-3:
Enter any Number : 224
Given Number is Not Armstrong Number 



Next Topic        :  

Previous Topic :

No comments:

Post a Comment