Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

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

Post New Answer

More C Interview Questions

What is the purpose of realloc()?

0 Answers  


Explain what is the benefit of using #define to declare a constant?

0 Answers  


What are the general description for loop statement and available loop types in c?

0 Answers  


f(*p) { p=(char *)malloc(6); p="hello"; return; } main() { char *p="bye"; f(p); printf("%s",p); } what is the o/p?

7 Answers   Hughes,


why little endian and big endian came?y they using differently? y they not used commonly ?wt is application of little and big ?

1 Answers  


What is getch() function?

0 Answers  


could u able to tell about suresoft technical session

1 Answers  


Difference between Function to pointer and pointer to function

0 Answers  


Write a program to find factorial of a number using recursive function.

0 Answers   Global Logic, TCS,


what is structuer?

4 Answers   LG Soft, Wipro,


What is function in c with example?

0 Answers  


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);

4 Answers   TCS,


Categories