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 ?    55 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

Write a program to replace n bits from the position p of the bit representation of an inputted character x with the one's complement. Method invertBit takes 3 parameters x as input character, p as position and n as the number of positions from p. Replace n bits from pth position in 8 bit character x. Then return the characters by inverting the bits.

0 Answers   Infosys,


Can a variable be both constant and volatile?

0 Answers  


What is huge pointer in c?

0 Answers  


What is the process to generate random numbers in c programming language?

0 Answers  


What is the role of && operator in a program code?

0 Answers  






Can you write the algorithm for Queue?

0 Answers   College School Exams Tests, TCS,


how do we remove the printed character in printf statement and write next it it

1 Answers  


Difference between C and Embedded C?

1 Answers  


What is a Genralised LInked List?? Please give a detailed explation of it..

1 Answers  


#include<string.h> void main() { String s1[]={"swathi"}; string s2[]={"maddimsetti"}; s1[]=s[]; printf("%s",s1[]); }

3 Answers   IBM,


Go through this linked list concept.While traversing through the singly linked list sometimes the following code snippet "while(head != NULL)" is used and other times "while(head->link != NULL)"is used(Here head is the pointer pointing to the first node,node has two parts data part and link part).What is the difference between head != NULL and Head->link != NULL and in which situation are they used?

1 Answers   Oracle,


What are the primitive data types in c?

0 Answers  


Categories