Strong Number: If sum of the factorials of the individual digits of a number is equal to that number then that number is said to be a Strong number.
Program:
import java.io.*;
class Strong
{
public static void main(String args[]) throws IOException
{
int strong=0;
System.out.println("Enter Number");
DataInputStream din=new DataInputStream(System.in);
int number=Integer.parseInt(din.readLine());
int temp=number;
while(temp>0)
{
int rem=temp%10;
strong=strong+fact(rem);
temp=temp/10;
}
if(strong==number)
{
System.out.println(number+" is a Strong Number");
}
else
{
System.out.println(number+" is not a Strong Number");
}
}
public static int fact(int n)
{
int fact=1;
for(int i=1;i<=n;i++)
{
fact=fact*i;
}
return(fact);
}
}import java.io.*;
class Strong
{
public static void main(String args[]) throws IOException
{
int strong=0;
System.out.println("Enter Number");
DataInputStream din=new DataInputStream(System.in);
int number=Integer.parseInt(din.readLine());
int temp=number;
while(temp>0)
{
int rem=temp%10;
strong=strong+fact(rem);
temp=temp/10;
}
if(strong==number)
{
System.out.println(number+" is a Strong Number");
}
else
{
System.out.println(number+" is not a Strong Number");
}
}
public static int fact(int n) //Function for calculating Factorial
{
int fact=1;
for(int i=1;i<=n;i++)
{
fact=fact*i;
}
return(fact);
}
}
Output:
C:\Users\ADITYA\Desktop>java Strong
Enter Number
145
145 is a Strong Number
C:\Users\ADITYA\Desktop>java Strong
Enter Number
144
144 is not a Strong Number
C:\Users\ADITYA\Desktop>
Program:
import java.io.*;
class Strong
{
public static void main(String args[]) throws IOException
{
int strong=0;
System.out.println("Enter Number");
DataInputStream din=new DataInputStream(System.in);
int number=Integer.parseInt(din.readLine());
int temp=number;
while(temp>0)
{
int rem=temp%10;
strong=strong+fact(rem);
temp=temp/10;
}
if(strong==number)
{
System.out.println(number+" is a Strong Number");
}
else
{
System.out.println(number+" is not a Strong Number");
}
}
public static int fact(int n)
{
int fact=1;
for(int i=1;i<=n;i++)
{
fact=fact*i;
}
return(fact);
}
}import java.io.*;
class Strong
{
public static void main(String args[]) throws IOException
{
int strong=0;
System.out.println("Enter Number");
DataInputStream din=new DataInputStream(System.in);
int number=Integer.parseInt(din.readLine());
int temp=number;
while(temp>0)
{
int rem=temp%10;
strong=strong+fact(rem);
temp=temp/10;
}
if(strong==number)
{
System.out.println(number+" is a Strong Number");
}
else
{
System.out.println(number+" is not a Strong Number");
}
}
public static int fact(int n) //Function for calculating Factorial
{
int fact=1;
for(int i=1;i<=n;i++)
{
fact=fact*i;
}
return(fact);
}
}
Output:
C:\Users\ADITYA\Desktop>java Strong
Enter Number
145
145 is a Strong Number
C:\Users\ADITYA\Desktop>java Strong
Enter Number
144
144 is not a Strong Number
C:\Users\ADITYA\Desktop>
can you explain a programe in c output like as
ReplyDelete1
2 3
4 5 6
7 8
9