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

There seem to be a few missing operators ..

814


What is the difference between struct and typedef struct in c?

887


Where does the name "C" come from, anyway?

869


How are pointers declared in c?

797


How many levels of pointers have?

796


Why can’t we compare structures?

1041


What is array of pointers to string?

795


Hai what is the different types of versions and their differences

1725


Explain what is gets() function?

818


What is a macro, and explain how do you use it?

825


How many types of functions are there in c?

797


Explain how do you sort filenames in a directory?

804


How can you access memory located at a certain address?

864


Differentiate between the = symbol and == symbol?

926


What is uint8 in c?

878