Check whether a given number is a strong number or not

Write a C program to check whether a given number is a strong number or not. or Write a program to check whether a given number is a strong number or not in C.

Program in C

Code:

/*Write a C program to check whether a given number is a strong number or not. or Write a program to check whether a given number is a strong number or not Using C*/

#include<stdio.h>
int main()
{
    int num,i;
    printf("Enter a number:");
    scanf("%d",&num);
    int num2=num;
    int sum=0;
    int fact=1;
   while(num!=0)
   {   fact=1;
       int rem=num%10;
       num=num/10;
       for(i=1;i<=rem;i++)
        fact=fact*i;
       sum=sum+fact;
   }
   if(sum==num2)
    printf("It is a Strong Number");
   else
    printf("It is not a Strong Number");
}

Input/Output:
Enter a number:145
It is a Strong Number

Write a C++ program to check whether a given number is a strong number or not. or Write a program to check whether a given number is a strong number or not in C++.

Program in C++

Code:

/*Write a C++ program to check whether a given number is a strong number or not. or Write a program to check whether a given number is a strong number or not using C++*/

#include<iostream>
using namespace std;
int main()
{
    int num;
    cout<<"Enter a number:";
    cin>>num;
    int num2=num;
    int sum=0;
    int fact=1;
   while(num!=0)
   {   fact=1;
       int rem=num%10;
       num=num/10;
       for(int i=1;i<=rem;i++)
        fact=fact*i;
       sum=sum+fact;
   }
   if(sum==num2)
    cout<<"It is a Strong Number";
   else
    cout<<"It is not a Strong Number";
}

Input/Output:
Enter a number:205
It is not a Strong Number

Write a JAVA program to check whether a given number is a strong number or not. or Write a program to check whether a given number is a strong number or not in Java.

Program in Java

Code:

/*Write a JAVA program to check whether a given number is a strong number or not. or Write a program to check whether a given number is a strong number or not using Java*/

import java.util.Scanner;
public class StrongNumberOrNot {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int num;
    System.out.println("Enter a number:");
    num=cs.nextInt();
    int num2=num;
    int sum=0;
    int fact=1;
   while(num!=0)
   {   fact=1;
       int rem=num%10;
       num=num/10;
       for(int i=1;i<=rem;i++)
        fact=fact*i;
       sum=sum+fact;
   }
   if(sum==num2)
    System.out.println("It is a Strong Number");
   else
    System.out.println("It is not a Strong Number");
cs.close();
}
}

Input/Output:
Enter a number:
125
It is not a Strong Number

Write a PYTHON to check whether a given number is a strong number or not. or Write a program to check whether a given number is a strong number or not in Python.

Program in Python

Code:

'''Write a Python program to check whether a given number is a strong number or not. or 
Write a program to check whether a given number is a strong number or not using Python '''

num=int(input("Enter a number:"))
num2=num
sum=0
while(num!=0):
   fact=1
   rem=num%10
   num=int(num/10)
   for i in range(1,rem+1):
      fact=fact*i
   sum=sum+fact
if sum==num2:
   print("It is a Strong Number")
else:
   print("It is not a Strong Number")

Input/Output:
Enter a number:555
It is not a Strong Number







Post a Comment

0 Comments