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

Explain what does the function toupper() do?

845


What is string length in c?

845


Explain the array representation of a binary tree in C.

962


i have a written test for microland please give me test pattern

2488


Why pointers are used?

845


Why can arithmetic operations not be performed on void pointers?

830


What are type modifiers in c?

827


What does printf does?

998


Is main is user defined function?

872


Explain the binary height balanced tree?

917


What is #include stdio h?

913


what do u mean by Direct access files? then can u explain about Direct Access Files?

1858


What is the process to create increment and decrement stamen in c?

812


Is linux written in c?

808


What is the significance of an algorithm to C programming?

817