> armstrong number in c ~ Online tutorial

armstrong number in c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

void main()
{
        long num1,num2=0,mcount=0, nums;
        char str1[35], strc;

        clrscr();
        printf("Enter a number : ");
        scanf("%ld",&num1);

         ltoa(num1,str1,10);
         while (mcount <= (strlen(str1)-1))
         {
          strc = str1[mcount];
          nums = atoi(&strc);
          num2 = num2+pow(nums,3);
          mcount = mcount+1;
         }

         if (num1 == num2)
         {
          printf("Amstrong Number : %ld",num2);
         }
         else
         {
          printf("Not a Amstrong Number.");
         }
   getch();
}
 

Please Give Us Your 1 Minute In Sharing This Post!
Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Powered By: BloggerYard.Com

0 comments: