fork download
  1. /**
  2.  * C program to print all Strong Numbers between 1 to n
  3.  */
  4.  
  5. #include <stdio.h>
  6.  
  7. int main()
  8. {
  9. int i, j, cur, n;
  10. long fact, sum;
  11.  
  12. /* Reads a number from user */
  13. printf("Find Strong numbers between 1 to ");
  14. n= 6000000;
  15.  
  16.  
  17.  
  18. printf("All Strong numbers between 1 to %d are:\n", n);
  19.  
  20. /* Finds all Strong numbers between 1 to n */
  21. for(i=1; i<=n; i++)
  22. {
  23. /* Number to check whether it is Strong number or not */
  24. cur = i;
  25.  
  26. sum = 0;
  27.  
  28. /*
  29.   * Finds the sum of factorial of each digits
  30.   */
  31. while(cur!=0)
  32. {
  33. fact = 1;
  34.  
  35. /* Computes factorial of last digit i.e. cur%10 */
  36. for( j=1; j<=cur%10; j++)
  37. {
  38. fact = fact * j;
  39. }
  40.  
  41. sum = sum + fact;
  42.  
  43. cur = cur / 10;
  44. }
  45.  
  46. /*
  47.   * Checks if it is Strong number then print it
  48.   */
  49. if(sum==i)
  50. {
  51. printf("%d is Strong number\n", i);
  52. }
  53. }
  54.  
  55. return 0;
  56. }
Success #stdin #stdout 0.32s 2168KB
stdin
10
stdout
Find Strong numbers between 1 to All Strong numbers between 1 to 6000000 are:
1 is Strong number
2 is Strong number
145 is Strong number
40585 is Strong number