DEV Community

gauravftp
gauravftp

Posted on

strong number between 1 to 10 in c program

In this article, we will see how you can calculate strong number from 1 to 10.
Strong number is a special number whose sum of the factorial of digits is equal to the original number

#include <stdio.h>

int factorial(int a);
int main() {
  int fact = 1, sum = 0;
  int n, r;
  n = 10;
  printf("Strong numbers are :");
  for (int i = 1; i <= n; i++) {
    int k = i;
    while (k != 0) {
      r = k % 10;
      fact = factorial(r);
      k = k / 10;
      sum = sum + fact;
    }
    if (sum == i) {
      printf("%d, ", i);
    }
    sum = 0;
  }
  return 0;
}
int factorial(int f) {
  int fact = 1;
  for (int i = 1; i <= f; i++) {
    fact = fact * i;
  }
  return fact;
}
Enter fullscreen mode Exit fullscreen mode

output:
Strong numbers are :1, 2

check strong number in c
even or odd in php

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more