Advertisement
Realratnadwip

Armstrong Number[Range]

May 13th, 2025
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.08 KB | Source Code | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <math.h>
  4. #include <stdlib.h>
  5.  
  6. void main()
  7. {
  8.   long int i, up, down, num, bnum, count, sum, digit, expo, flag = 0;
  9.   system("cls");
  10.   printf("This is a simple program to print Aarmstrong Number.\n\n");
  11.   printf("Enter The upper range : ");
  12.   scanf("%ld",&up);
  13.   printf("Enter The lower range : ");
  14.   scanf("%ld", &down);
  15.   system("cls");
  16.   printf("Armstrong-Numbers in ascending order.\n\n");
  17.   for (i = down; i <= up; i++)
  18.   {
  19.     num = i;
  20.     bnum = i;
  21.     count = 1;
  22.     while (bnum / 10 != 0)
  23.     {
  24.       bnum = bnum / 10;
  25.       count++;
  26.     }  
  27.     sum = 0;
  28.     while (num > 0)
  29.     {
  30.       digit = num % 10;
  31.       expo = pow(digit,count);
  32.       sum = sum + expo;
  33.       num = num / 10;
  34.     }
  35.     if (sum == i)
  36.     {      
  37.       printf("%ld\n", i);
  38.       flag++;
  39.     }
  40.   }
  41.   if (flag == 0)
  42.   {
  43.     system("cls");
  44.     printf("There is no Armstrong-Number in this range.");
  45.   }
  46.   else
  47.   {
  48.     printf("\nThere is total '%ld' Armstrong-Number in this range.", flag);
  49.   }
  50.   printf("\n\n\n");
  51.   system("pause");
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement