Advertisement
Divyansh_Chourey

Strong numbers

Mar 18th, 2024
472
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.37 KB | Source Code | 0 0
  1. #include<stdio.h>
  2. int main(){
  3.     int n, i, j, fact, sum;
  4.     printf("Enter the number: ");
  5.     scanf("%d", &n);
  6.     printf("Strong number between 1 to %d are: \n", n);
  7.     for(i = 1; i <= n; i++){
  8.         sum =0;
  9.         j = i;
  10.         while(j > 0){
  11.             fact = 1;
  12.             for(int k = 1; k <= j%10; k++)
  13.             fact *= k;
  14.             sum += fact;
  15.             j /= 10;
  16.         }
  17.         if(sum == i)
  18.             printf("%d\n", i);
  19.     }
  20.     return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement