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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How variables are declared in c?

577


How can I generate floating-point random numbers?

613


What is a pointer value and address in c?

637


#include int main(){ int i=10; int *ptr=&i; *ptr=(int *)20; printf("%d",i); return 0; } Output: 20 can anyone explain how came the output is 20

1269


Can a variable be both constant and volatile?

567






What is variable declaration and definition in c?

506


process by which one bit patten in to another by bit wise operation is? (a) masking, (b) pruning, (c) biting, (d) chopping,

1895


What is a union?

615


Explain what is the difference between null and nul?

664


Explain what is output redirection?

670


hi folks i m approching for h1 b interview on monday 8th of august at montreal and i m having little problem in my approval notice abt my bithdate my employer has made a mistake while applying it is 12th january and istead of that he had done 18 the of january do any body have any solution for that if yes how can i prove my visa officer abt my real birthdate it urgent please let me know guys thaks dipesh patel

1417


Why is it that not all header files are declared in every C program?

687


What is string concatenation in c?

573


What are loops c?

624


What are pointers? Why are they used?

635