write a program to check whether a number is Peterson or not.

Answers were Sorted based on User's Feedback



write a program to check whether a number is Peterson or not...

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

write a program to check whether a number is Peterson or not...

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

write a program to check whether a number is Peterson or not...

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 15 No

Post New Answer

More C Interview Questions

What are data breakpoints?

3 Answers   Adobe,


extern static int i func() { i =10; i++; printf("%d \n",i); } main() { i =20; printf("%d \n",i); func(); printf("%d \n",i); }

2 Answers  


what is the use of using linked list and array?

10 Answers   Infosys, TCS,


Why should I use standard library functions instead of writing my own?

0 Answers  


in a town the percentage of men is 52 the percentage of total literacy is 48 if total percentage of literate men is 35 of the total population write a program to find the total no of the literate men and women if the population of the town is 80000

3 Answers  






What is quick sort in c?

0 Answers  


Can we use any name in place of argv and argc as command line arguments?

0 Answers  


Explain how do you determine a file’s attributes?

0 Answers  


Write the following function in C. stripos — Find position of first occurrence of a case- insensitive string int stripos ( char* haystack, char* needle, int offset ) Returns the numeric position of the first occurrence of needle in the haystack string. Note that the needle may be a string of one or more characters. If needle is not found, stripos() will return - 1. The function should not make use of any C library function calls.

3 Answers   Google, Infosys, JTL, OpenFeel,


What is the function of volatile in c language?

0 Answers  


List out few of the applications that make use of Multilinked Structures?

1 Answers   Accenture,


write a program to remove occurrences the word from entered text?

1 Answers  


Categories