Strong Number in C programming --- Learning Duniya
What will be the programming for Strong Number?
Today topic is Strong Number . We will discuss about Strong Number, what is Strong Number, example of it, it's programming logic and output either a given number is Strong Number or not.
What is Strong Number?
Strong Number are such number whose factorial sum of its digit is equal to that number is called Strong Number. Means a sum of digit factorial is equal to that number.
Example:
lets take a number 145.
145 digits are 1, 4, 5 and its factorial sum :- 1! + 4! + 5!= 1+ 24 + 120 = 145 . Which is equal to the original number, then this number is Strong Number.
Lets take another number 123.
123 digits are 1, 2, 3 and its factorial sum :- 1! +2! + 3! = 1+ 2 + 6 = 9 which is not equal to original number, then it in Not Strong Number.
Programming:-
#include<stdio.h>
#include<conio.h>
int main()
{
int num, i, temp,count, temp1,newNum = 0; //Data type deceleration.
printf("Enter teh number to check either it is strong number or not");
scanf("%d",&num); //User input.
temp = num;
while(temp>0) //For spliting number.
{
temp1= temp%10;
count = 1;
for(i=1; i<=temp1; i++) //For factorial.
{
count = count*i;
}
newNum = newNum + count;
temp= temp/10;
}
if(newNum == num) //Comparing the new number to original Number.
{
printf("%d is a Strong number ",num);
}
else
{
printf("%d is not a Strong number ",num);
}
getch();
return 0;
}
Output:-
Fig :-2
Logic:-
By knowing the definition of Strong Number, we know that sum of factorial digit is equal to original number then it will Strong Number. For spiting digit of number we have use While loop and inside it we have use For loop to find the factorial and its sum. After that we have use if else condition to compare new number with the original number and if it equal then we are printing Strong Number if not equal then not strong number.
If you face any problem then comment in comment section or visit my YouTube Channel to understand the logic. All videos are in Hindi language.
🤘
ReplyDeleteawsam
ReplyDelete