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


Please Help Members By Posting Answers For Below Questions

How can you tell whether a program was compiled using c versus c++?

613


The performance of an operation in several steps with each step using the output of the preceding step a) recursion b) search c) call by value d) call by reference

666


What is the value of c?

562


string reverse using recursion

1801


please can any one suggest me best useful video tutorials on c i am science graduate.please help me.u can email me to sas29@in.com

1314






What is unsigned int in c?

549


How can I open files mentioned on the command line, and parse option flags?

581


Is multithreading possible in c?

557


What does typedef struct mean?

644


swap 2 numbers without using third variable?

652


How can I read a binary data file properly?

626


Write a program to know whether the input number is an armstrong number.

660


How is a pointer variable declared?

582


What type of function is main ()?

574


Is swift based on c?

624