In this tutorial you will learn about the C program to check Strong Number and its application with practical example.
C Program to check Strong Number
In this tutorial, we will learn to create a C program that will check Strong Number in C programming.
Prerequisites
Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- While loop in C programming.
What is a Strong number?
A strong number is a number whose sum of all digits’ “S” factorial is equal to the number “N”. Let S be the sum of FACTORIAL of all the digits in a number is equal to its original number.
1 2 3 4 5 |
<strong>For Example: 145 is a strong number. Since, 1! + 4! + 5! = 145. </strong> |
Algorithm:-
1 2 3 4 5 6 7 8 9 |
1. Declare the variables for the program. 2. Taking the input number from the user to check. 3. Checking if the number is the <strong>strong Number or Not</strong>. 4. Print the Result. 5. End the program. |
Program For checking a strong number:-
In today’s tutorial, we will take the input number from the user. Then we will Check the Number is strong number or not. At last, we will print the number is a strong number or not.
With the help of this program, we can check Strong Number.
Program Code:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
/* * C program to check Strong number * */ #include <stdio.h> int main() { /* Declaring the required variables for the program. */ int i, orgno, no, lastDigit, sum; long fact; /* Taking input number from the user for the checking of strong number */ printf("Enter number to check Strong number: "); scanf("%d", &no); /* Copy the value of no to a temporary variable */ orgno = no; sum = 0; /* Find sum of factorial of the digits */ while(no > 0) { /* Get last digit of no */ lastDigit = no % 10; /* Finding the factorial of last digit */ fact = 1; for(i=1; i<=lastDigit; i++) { fact = fact * i; } /* Add factorial to sum */ sum = sum + fact; no = no / 10; } /* Check Strong number condition */ if(sum == orgno) { //Printing the output after checking the number printf("%d is STRONG NUMBER", orgno); } else { //Printing the output after checking the number printf("%d is NOT STRONG NUMBER", orgno); } return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- no = it will hold the integer value.
- orgno = it will hold the integer value.
- lastDigit = it will hold the integer value.
- sum = it will hold the integer value.
- fact = it will hold the float value.
Taking the input integer number from the user.