Become Our Fan on Social Sites!

Facebook Twitter

Google+ RSS YouTube

Thursday, 26 September 2013

Armstrong number using C language

Armstrong Number: If the sum of cubes of individual digits of a number is equal to the number itself is called Armstrong Number. For Example 371 is an Armstrong number that means 33 + 73 + 13 = 371 that is number itself. Some Armstrong numbers are: 0, 1, 153, 370, 371, 407.




#include <stdio.h>

int main()
{
    int no, t, sum = 0, r;

    printf("Enter No : ");
    scanf("%d",&no);

    t = no;

    while( t != 0 )
    {
        r = t % 10;
        sum = sum + r * r * r;
        t = t / 10;
    }

    if ( no == sum )
        printf("Armstrong Number");
    else
        printf("Not Armstrong Number");

    return 0;
}


1 comments :

  1. Nice and Useful Post...helps me a lot...keep posting

    ReplyDelete