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 / abhijit
using System;
using System.Collections.Generic;
using System.Text;
namespace Practice
{
class Program
{
public static int fact(int r)
{
if (r == 0 || r == 1)
return 1;
else
return (r * fact(r - 1));
}
static void Main(string[] args)
{
args = new string[1];
args[0] = Console.ReadLine();
int n, tmp, rem, sum = 0;
int ii = fact(5);
n = Convert.ToInt32(args[0]);
tmp = n;
int jj=0;
while (n != 0)
{
rem = n % 10;
jj=fact(rem);
sum = sum + jj;
n = n / 10;
}
if (tmp == sum)
Console.WriteLine(tmp + "is a strong number");
else
Console.WriteLine(tmp + " is not a strong number");
Console.ReadLine();
}
}
}
| Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
What happens if a header file is included twice?
What does a function declared as pascal do differently?
What do you mean by Recursion Function?
What are derived data types in c?
What are structure members?
How old is c programming language?
what is the function of pragma directive in c?
I heard that you have to include stdio.h before calling printf. Why?
Why are all header files not declared in every c program?
What is c language and why we use it?
What is use of pointer?
Are c and c++ the same?
What is the difference between far and near ?
What does == mean in texting?
What is the use of typedef in c?