Strong number program

Strong number in c

#include<stdio.h>
#include<conio.h>
void CheckStrong(int number);
int Factorial(int fact);

void main()
{
	int input;
	printf("Enter your number \n");
	scanf("%d",&input);
	CheckStrong(input);
	getch();
}
void CheckStrong(int number)
{
    int r;
    int s = 0;
    int p = number;
    while (number > 0)
    {
        r = number % 10;
        s += Factorial(r);
        number /= 10;
    }
    if (p == s)
        printf("Yes, it is a strong number");
    else
        printf("No, it is not a strong number");
}
int Factorial(int fact)
{
    int total = 1;
    for (int i = fact; i >= 1; i--)
    {
        total *= i;
    }
    return total;
}

Output

Enter your number
145
Yes, it is a strong number

Strong number in c++

#include<iostream>
#include<conio.h>
using namespace std;
class Example
{
public:
	int Factorial(int fact)
        {
            int total = 1;
            for (int i = fact; i >= 1; i--)
            {
                total *= i;
            }
            return total;
        }
public:
	void CheckStrong(int number)
        {
            int r;
            int s = 0;
            int p = number;
            while (number > 0)
            {
                r = number % 10;
                s += Factorial(r);
                number /= 10;
            }
            if (p == s)
                cout<<"Yes, it is a strong number";
            else
                cout<<"No, it is not a strong number";
        }
};
void main()
{
	int input;
	Example ex;
	cout<<"Enter your number \n";
	cin>>input;
	ex.CheckStrong(input);
	getch();
}

Output

Enter your number
146
No, it is not a strong number

Strong number in c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CheckStrongNumber
{
    class Program
    {
        public int Factorial(int fact)
        {
            int total = 1;
            for (int i = fact; i >= 1; i--)
            {
                total *= i;
            }
            return total;
        }
        public bool CheckStrong(int number)
        {
            int r;
            int s = 0;
            int p = number;
            while (number > 0)
            {
                r = number % 10;
                s += Factorial(r);
                number /= 10;
            }
            if (p == s)
                return true;
            else
                return false;
        }
        static void Main(string[] args)
        {
            Program p1=new Program();
            Console.WriteLine("Enter your number");
            int input = Convert.ToInt32(Console.ReadLine());
            if (p1.CheckStrong(input))
            {
                Console.Write("Yes, it is a strong number");
            }
            else
            {
                Console.Write("No, it is not a strong number");
            }
            Console.ReadLine();
        }
    }
}

Output

Enter your number
145
Yes, it is a strong number

Strong number in java

import java.util.*;
class AB
{
	public int Factorial(int fact)
    {
        int total = 1;
        for (int i = fact; i >= 1; i--)
        {
            total *= i;
        }
        return total;
    }
    public boolean CheckStrong(int number)
    {
        int r;
        int s = 0;
        int p = number;
        while (number > 0)
        {
            r = number % 10;
            s += Factorial(r);
            number /= 10;
        }
        if (p == s)
            return true;
        else
            return false;
    }
	
}
class examples
{
public static void main(String[] args)
	{
     int input;
     Scanner obj= new Scanner(System.in);
     System.out.println("Enter your number");
     input=obj.nextInt();
     
     AB ab=new AB();
     if(ab.CheckStrong(input))
     {
      System.out.println("Yes, it is a strong number");
     }
     else
     {
    	 System.out.println("No, it is not a strong number");
     }
     
	}

}

Output

Enter your number
146
No, it is not a strong number

Write a comment


Name Email Message