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
program to find out date after adding 31 days to a date in the month of febraury also consider the leap year
Is the exit() function same as the return statement? Explain.
Explain what is the difference between a string and an array?
number of times a digit is present in a number
Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal. [ I gave the obvious solution of taking % 10 and / 10, which gives us the decimal value in reverse order. This requires an array since we need to print it out in the correct order. The interviewer wasn't too pleased and asked me to give a solution which didn't need the array ].
What do you mean by c what are the main characteristics of c language?
If a variable is a pointer to a structure, then which operator is used to access data members of the structure through the pointer variable?
Is it possible to have a function as a parameter in another function?
What are static variables in c?
What is formal argument?
What is the difference between malloc() and calloc() function in c language?
in case any function return float value we must declare a) the function must be declared as 'float' in main() as well b) the function automatically returned float values c) function before declared 'float' keyword d) all the above
What would the following code segment printint k = 8;docout << "k = " << k << " ";while k++ < 5; a) 13 b) 5 c) 8 d) pointers
Is multithreading possible in c?
What is the difference between volatile and const volatile?