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 |
What is the purpose of realloc()?
Explain what is the benefit of using #define to declare a constant?
What are the general description for loop statement and available loop types in c?
f(*p) { p=(char *)malloc(6); p="hello"; return; } main() { char *p="bye"; f(p); printf("%s",p); } what is the o/p?
why little endian and big endian came?y they using differently? y they not used commonly ?wt is application of little and big ?
What is getch() function?
could u able to tell about suresoft technical session
Difference between Function to pointer and pointer to function
Write a program to find factorial of a number using recursive function.
what is structuer?
What is function in c with example?
what is the output on the screen? int n; n=printf("my name is %d",printf("kiran %d",printf("kumar"))); printf("\n %d \n",n);