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
Explain what is the benefit of using an enum rather than a #define constant?
how could explain about job profile
What is merge sort in c?
What are the different types of objects used in c?
Is swift based on c?
What is structure padding and packing in c?
What is a class c rental property?
In c programming write a program that will print 10 multiples of 3 except 15,18,21 using looping
Can you return null in c?
Why can't I perform arithmetic on a void* pointer?
What are the different types of control structures in programming?
What is a #include preprocessor?
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.
Explain what is a 'null pointer assignment' error? Explain what are bus errors, memory faults, and core dumps?
What is the difference between struct and typedef struct in c?