Advertisement
Realratnadwip

Armstrong Number

May 13th, 2025
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.73 KB | Source Code | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <stdlib.h>
  4.  
  5. void main()
  6. {
  7.     int num, bnum, i, j, count, sum, rem, power;
  8.    
  9.     printf("This is a simple program to check Armstrong Number.\n\n");
  10.     printf("Enter The number to check : ");
  11.     scanf("%d",&num);
  12.  
  13.     bnum = num;
  14.     count = 0;
  15.     while (bnum  != 0)
  16.     {
  17.         count++;
  18.         bnum = bnum / 10;
  19.     }
  20.     sum = 0;
  21.    
  22.     bnum = num;
  23.    
  24.     for(i = 1; i <= count; i++)
  25.     {
  26.         rem = bnum % 10;
  27.         power = 1;
  28.         for(j = 1; j <= count; j++)
  29.         {
  30.             power = power * rem;
  31.         }
  32.         sum = sum + power;
  33.         bnum = bnum / 10;
  34.     }
  35.    
  36.     if(sum == num)
  37.     {
  38.         printf("%d - is a Armstrong Number.", num);
  39.     }
  40.     else
  41.     {
  42.         printf("%d - is not a Armstrong Number.", num);
  43.     }
  44.    
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement