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 is the benefit of using an enum rather than a #define constant?

728


how could explain about job profile

1460


What is merge sort in c?

650


What are the different types of objects used in c?

581


Is swift based on c?

644






What is structure padding and packing in c?

627


What is a class c rental property?

620


In c programming write a program that will print 10 multiples of 3 except 15,18,21 using looping

983


Can you return null in c?

603


Why can't I perform arithmetic on a void* pointer?

641


What are the different types of control structures in programming?

664


What is a #include preprocessor?

625


Write a program to replace n bits from the position p of the bit representation of an inputted character x with the one's complement. Method invertBit takes 3 parameters x as input character, p as position and n as the number of positions from p. Replace n bits from pth position in 8 bit character x. Then return the characters by inverting the bits.

3694


Explain what is a 'null pointer assignment' error? Explain what are bus errors, memory faults, and core dumps?

647


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

663