Strong Number in C Using While Loop

Strong Number in C Using While Loop for beginners. A strong number is one whose factorial sum of all digits equals the number ‘n’. So, to determine a number, whether it is a strong number or not, we must select each digit of the number. For example, if the number is 145, we must select 1, 4, and 5; now we will find the factorial of each number, which is 1!

While Loop Definition

A “While” Loop is used to iterate over a certain piece of code until a condition is fulfilled.

A for loop is used when we (or the computer) know exactly how many times to execute a portion of code (such as shuffling a deck of cards).

A while loop is a control flow statement in most computer programming languages that allows code to be performed repeatedly based on a supplied Boolean condition.

The while loop may be viewed as a looping if statement.

Factorial Number in C

In mathematics, factorial is the product of all positive integers that are less than or equal to a particular positive integer, indicated by that integer plus an exclamation point.

If Else Statement in C

If a particular condition is true, the if/else statement executes a block of code. If the condition is not met, another piece of code can be run.

The if/else statement is a type of “Conditional” Statement in JavaScript, which is used to conduct different actions based on distinct situations.

#include<stdio.h>
int main()
{
int n;
int sum=0;
printf("Enter the number");
scanf("%d",&n);
int a=n;
int r;
while(a!=0)
{
r=a%10;
int f=fact(r);
a=a/10;
sum=sum+f;
}
if(sum==n)
{
printf("\nNumber is Strong");
}
else
{
printf("\nNumber is not Strong");
}
return 0;
}
int fact(int r)
{
int mul=1;
for(int i=1;i<=r;i++)
{
mul=mul*i;
}
return mul;
}

Output:

Enter the number 200

Number is not Strong