Saturday, 28 January 2017

C program to find a Number is Strong or not ~ mkniit ~ gniitsolution

C program to find a Number is strong or not. It is a simple source code that provides the output of an actual Strong number. Take care of a questions for your interviews or students exam. This is a totally free of cost code.


NUMBER IS STRONG OR NOT IN C

Number is strong in C program means it calculates the factorial value for the entire number. If the total of a factorial value is the same as given number, then this number is said to be a strong number. For example 125(1!+2!+5!=1+2+120=123) is weak number. Then the strong number is 145.

C CODE:
Q: Write a C program to check whether the given number is strong or not.
01
02
03
04
05
06
07
08
09
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
/* Title: Strong number program
Author: Vinoth Selvaraj
*/
//Header file section
#include <stdio.h>
#include <conio.h>
#include <math.h>
 
void main()
{
    //Program variables
    int value,num,temp=1,ans=0,cn,num1;
    clrscr(); //Function to clear previous output
 
    printf("Enter the value : "); //Display function
    scanf("%d",&num); //Getting input function
    value=num;
 
    //calculating number is strong or not
    while(num>0) //unconditional statement
    {
        temp=1;
        num1=num%10;
        for(cn=num1;cn>1;cn--)/ /Looping statement
        {
            temp=temp*cn;
 
        }
        num/=10;
        ans+=temp;
    }
    printf("ans = %d",ans);
    if(value==ans) //Conditional statement
        printf("Number is strong number");
 
    getch();
}

No comments:

Post a Comment