Friday, 14 October 2016

Write a C Program to Find Whether the Given Number is Armstrong number

4a2.c
Aim:- b)Write a C Program to Find Whether the Given Number is Armstrong number

Program:-

#include<stdio.h>
 main()
{
    int num,r,sum=0,temp;
    printf("Enter a number: ");
    scanf("%d",&num);
    temp=num;
    while(num!=0)
    {
         r=num%10;
         num=num/10;
         sum=sum+(r*r*r);
    }
    if(sum==temp)
    printf("%d is an Armstrong number",temp);
    else
    printf("%d is not an Armstrong number",temp);

}

No comments:

Post a Comment