C Program to Find Strong Number

Flow Control
If-else Statement in C
Programs on if-else
Switch Case in C
Switch case Programs
Conditional Operator
While loop in C
Do-while loop in C
While vs do-while
For loop in C
Break keyword in C
Continue keyword in C
Break vs Exit in C
Goto keyword in C
☕️ Flow Control Programs
Largest in 3 Numbers
Find Grade of student
Find the absolute value
Vowel or Consonant
Leap Year Program
Simple calculator in C
Check Odd or Even 
Roots of Quadratic Equation
Find Reverse of Number
Factors of a number in C
Generate Multiplication table
Find Power of a Number
Find GCD and LCM
Find factorial of Number
Count Number of Digits
Sum of digits in Number
Sum of N Natural Numbers
Sum of Squares of Natural No.
Find Sum of Odd Numbers
Find the Sum of Series
Find Fibonacci series in C
Sum of the Fibonacci series
Sum until enters +ve numbers
Sum of max 10 no. & Skip -ve
☕️ C Conversion Programs
Celsius to Fahrenheit
Fahrenheit to Celsius
Decimal ↔ Binary
Decimal ↔ Octal
Octal ↔ Binary in C
☕️ Number Programs in C
Prime Number in C
Strong Number in C
Krishnamurthy Number
Neon Number in C
Palindrome number
Perfect Number in C
Armstrong Number
☕️ Pattern Programs in C
Pattern programs in C
Printing pattern using loops
Floyd’s triangle Program
Pascal Triangle Program
Pyramid Star Pattern in C
Diamond Pattern Programs
Half Diamond pattern in C
Print Diamond Pattern
Hollow Diamond Pattern
Diamond Pattern of Numbers

We will write a C program to find a Strong number or Krishnamurthy Number. After that, we will write another C program to find a Strong Number in a given Range. First of all, we should know that what is Strong number? Prerequisite examples are factorial of a number and sum of digits in a given number.

Strong Number:- The sum of the factorial of individual digits of a number is equal to the same number. Sometimes the Strong number also called Krishnamurthy Number.

Example:-
145 = 1! + 4! + 5! = 1 + 24 + 120 = 145
So, 145 is a strong number.

234 = 2! + 3! + 4! = 2 + 6 + 24 = 32
So, 234 is not a strong number.

40585 = 4! + 0! + 5! + 8! + 5! = 24 + 1 + 120 + 40320 + 120 = 40585
So, 40585 is a strong number.


C program to check the number is Strong number or not

#include<stdio.h>
int main()
{
     int number, tempvariable, remainder, i, factorial, sum=0;

     printf("Enter number: ");
     scanf("%d",&number);

     tempvariable = number;

     while( number!=0 )
     {
         factorial = 1;  //every time factorial initialize with 1
         remainder = number%10;

         for(i=1; i<=remainder; i++)
         {
             factorial *= i; //factorial=factorial * i
         }

         sum += factorial;  //sum= sum+factorial
         number /= 10;  //numbar=numbar/10
     }

     if( tempvariable == sum )
         printf("%d is a strong number.\n",tempvariable);
     else
         printf("%d is not a strong number.\n",tempvariable);

     return 0;
}

Output:-

Enter number: 145
145 is a strong number.

Enter number: 500
500 is not a strong number.

Explanation:- The variables for this program are number, tempvariable, remainder, i, factorial, and sum. Variable tempvariable holds the value of the number, because finally we need to check that result is the same as the previously given number or not? Using while loop iteration starts with the condition that the variable number should not be equal to 0. We need to find the factorial of each digit in a given number.

After finding the factorial of each digit, the sum will be calculated. To find the factorial of each digit first we need to find the last digit of the variable number using the variable remainder. Now, factorial will be calculated. The addition of factorial of each digit will be calculated and stored into a variable sum.

Iteration will be ended when the number becomes equal to 0. Using an if-else conditional statement we will check that is the variable sum and the variable tempvariable is equal or not? If the answer is yes then the given number is a strong number otherwise it is not a strong number.

Strong number in a given range

Now, We will find Strong number in a given range. The Range starts from m and end at n.

#include<stdio.h>
int main()
{
     int m, n, i, num, j, fact, sum;

     printf("Enter the range m and n Values (m<n): ");
     scanf("%d %d",&m,&n);

     printf("Strong numbers are:\n");

     for(i=m; i<=n; i++)
     {
         num = i;
         sum = 0;

         while(num!=0)
         {
             fact=1;

             for(j=1;j<=(num%10);j++)
             {
                 fact *= j;
             }

             sum += fact; //sum=sum+fact
             num /= 10; //num=num/10
         }

         if(sum==i)
           printf("%d\n",i);
     }

     return 0;
 }

Output:-

Enter the range m and n Values (m<n): 1, 1000000
Strong numbers are:
1
2
145
40585

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!

Flow Control
If-else Statement in C
Programs on if-else
Switch Case in C
Switch case Programs
Conditional Operator
While loop in C
Do-while loop in C
While vs do-while
For loop in C
Break keyword in C
Continue keyword in C
Break vs Exit in C
Goto keyword in C
☕️ Flow Control Programs
Largest among 3 Numbers
Find Grade of student
Find the absolute value
Check Vowel or Consonant
Leap Year Program
Simple calculator in C
Check Odd or Even 
Roots of Quadratic Equation
Find Reverse of Number
Factors of a number in C
Generate Multiplication table
Find Power of a Number
Find GCD and LCM
Find factorial of Number
Count Number of Digits
Sum of digits in Number
Sum of N Natural Numbers
Sum of Squares of Natural No.
Find Sum of Odd Numbers
Find the Sum of Series
Find Fibonacci series in C
Sum of the Fibonacci series
Sum until enters +ve numbers
Sum of max 10 no. & Skip -ve
☕️ C Conversion Programs
Celsius to Fahrenheit
Fahrenheit to Celsius
Decimal ↔ Binary
Decimal ↔ Octal
Octal ↔ Binary in C
☕️ Number Programs in C
Prime Number in C
Strong Number in C
Krishnamurthy Number
Neon Number in C
Palindrome number
Perfect Number in C
Armstrong Number
☕️ Pattern Programs in C
Pattern programs in C
Printing pattern using loops
Floyd’s triangle Program
Pascal Triangle Program
Pyramid Star Pattern in C
Diamond Pattern Programs
Half Diamond pattern in C
Print Diamond Pattern
Hollow Diamond Pattern
Diamond Pattern of Numbers

Leave a Comment

Your email address will not be published. Required fields are marked *