write a program to check whether a number is Peterson or not.
Answers were Sorted based on User's Feedback
Answer / rama krishna sidhartha
Peterson number means sum of factorials of digits of a given
number.
//code :
#include<stdio.h>
#include<conio.h>
void main()
{
int n,c,s=0,m,i,f=1;
clrscr();
printf("\n ENTER A VALUE : ");
scanf("%d",&n);
m=n;
while(n>o)
{
c=n%10;
for(i=0;i<c;i++)
f=f*i;
s=s+f;
f=1;
n=n/10;
}
if(s==m)
printf("\n THE ENTERED NUMBER IS PETERSON
NUMBER.");
else
printf("\n THE ENTERED NUMBER IS NOT A
PETERSON NUMBER.");
getch();
}
| Is This Answer Correct ? | 56 Yes | 22 No |
Answer / prasanna kumar
N = int(input("Enter a number: "))
original_num = N
sum_of_factorials = 0
while N > 0:
digit = N % 10
fact = 1
for i in range(1, digit + 1):
fact = fact * i
sum_of_factorials = sum_of_factorials + fact
N = N // 10
if sum_of_factorials == original_num:
print(f"{original_num} is a Peterson number")
else:
print(f"{original_num} is not a Peterson number")
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / lalabs
void find_peterson_num ( int num )
{
int sum;
int fact, i;
int temp = num;
do
{
for ( i = 1, fact = 1; i <= (temp % 10); i++)
{
fact *= i;
}
sum += fact;
temp /= 10;
} while ( temp > 0);
if ( sum == temp )
{
printf ( "%d is Perterson number of %d\n", num, sum );
}
printf ( "%d is NOT Perterson number of %d\n", num, sum );
}
| Is This Answer Correct ? | 8 Yes | 12 No |
Answer / deeksha shaw
import java.util.Scanner;
public class peterson
{
public static void main(String args[])
{
int n,f=1;
Scanner in=new Scanner(System.in);
System.out.println("enter a number");
n=in.nextInt();
for(int a=1;a<=n;a++)
f=f*a;
if (f==n)
System.out.println(" it is a Peterson number");
else
System.out.println("it is not a Peterson number");
}
}
| Is This Answer Correct ? | 11 Yes | 16 No |
Do pointers store the address of value or the actual value of a variable?
how much salary u want ? why u join in our company? your domain is core sector why u prefer software ?
Tell us the use of fflush() function in c language?
What is a struct c#?
Write a main() program that calls this function at least 10 times. Try implementing this function in two different ways. First, use an external variable to store the count. Second, use a local variable. Which is more appropriate?
What is variable initialization and why is it important?
What are volatile variables in c?
what is the c source code for the below output? 5555555555 4444 4444 333 333 22 22 1 1 22 22 333 333 4444 4444 5555555555
Write a c program to find, no of occurance of a given word in a file. The word is case sensitive.
What are formal parameters?
What is the difference between the = symbol and == symbol?
What is 1f in c?