write a program to check whether a given integer is a strong
number or not?
[Hint:
145=1!+4!+5!
=1+24+120
=145]
Answer Posted / paul zarkovich
#include<iostream>
#include<stdio.h>
#include<conio.h>
using namespace std;
main()
{
int n,fact=1,sum=0,digit=0;
printf("Enter a number : ");
scanf("%d",&n);
int temp=n,a=n;
if(temp<10)
{
for(int i=temp;i>0;i--)
fact*=i;
if(n==fact)
printf("It is a strong no. ");
else
printf("It is not a strong no. ");
}
else
{
while(temp>10)
{
digit=temp%10;
temp/=10;
for(int i=digit;i>0;i--)
fact*=i;
sum+=fact;
fact=1;
}
for(int i=temp;i>0;i--)
fact*=i;
sum+=fact;
if(sum==n)
printf("It is a strong no. ");
else
printf("It is not a strong no. ");
}
getch();
}
| Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
What are loops in c?
What does 3 mean in texting?
how to execute a program using if else condition and the output should enter number and the number is odd only...
What is wild pointer in c with example?
Read the following data in two different files File A: aaaaaaaadddddddd bbbbbbbbeeeeeeee ccccccccffffffff File B: 11111111 22222222 33333333 By using the above files print the following output or write it in the Other file as follows aaaaaaaa11111111dddddddd bbbbbbbb22222222eeeeeeee cccccccc33333333ffffffffffff
What is the use of volatile?
Hai,I have done with my bachelor of commerce and planing to ms,please suggest me how to convince vo for shifting from commerce to computers. Visa on 8 DEC 2014 Npu university
What is the difference between pure virtual function and virtual function?
Want to know how to write a C program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL.
What is a structural principle?
in multiple branching construct "default" case is a) optional b) compulsarily c) it is not include in this construct d) none of the above
How do you use a 'Local Block'?
What is the main difference between calloc () and malloc ()?
Create a simple code fragment that will swap the values of two variables num1 and num2.
What is volatile keyword in c?