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 does the function toupper() do?
What is string length in c?
Explain the array representation of a binary tree in C.
i have a written test for microland please give me test pattern
Why pointers are used?
Why can arithmetic operations not be performed on void pointers?
What are type modifiers in c?
What does printf does?
Is main is user defined function?
Explain the binary height balanced tree?
What is #include stdio h?
what do u mean by Direct access files? then can u explain about Direct Access Files?
What is the process to create increment and decrement stamen in c?
Is linux written in c?
What is the significance of an algorithm to C programming?