Program to check if a given number is a strong number or not | faceprep

Program to check if a given number is a strong number or not | faceprep

A program to check if a given number is a strong number or not is discussed here. A strong number is a number in which the sum of the factorial of the digits is equal to the number itself.


Program to check if a given number is a strong number or not



Program to check if a given number is a strong number or not @@coding::1@@

Using Command Line Argument

The given number N, a positive integer, will be passed to the program using the first command line parameter.

If it is a strong number, the output should be YES, If it is not a prime number then output should be NO to stdout.

Other than YES or NO, no other extra information should be printed to stdout.


#include<stdio.h>n#include<stdlib.h>nint main(int a, char *b[])n{nint number, i, temp, sum = 0, factorial = 1;nnumber = atoi(b[1]);ntemp = number;nwhile(number != 0)n{nint rem = number%10;nfor(i=2; i<=rem; i++)n{nfactorial = factorial * i;n}nsum = sum + factorial;nnumber = number/10;nfactorial = 1;n}nif(temp == sum)nprintf("YES");nelsenprintf("NO");nreturn 0;n}n


check-if-a-given-number-is-strong-number-or-not


Recommended Programs











check-if-a-given-number-is-strong-number-or-not-1

c