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
Write a program of advanced Fibonacci series.
This is a variation of the call_me function in the previous question:call_me (myvar)int *myvar;{ *myvar += 5; }The correct way to call this function from main() will be a) call_me(myvar) b) call_me(*myvar) c) call_me(&myvar) d) expanded memory
Can you explain what keyboard debouncing is, and where and why we us it? please give some examples
What is a function simple definition?
Explain what is dynamic data structure?
Hai sir, I had planned to write the NIC scientific engineer exam , plz post the sample question......
What is mean by data types in c?
Can i use “int” data type to store the value 32768? Why?
What are identifiers and keywords in c?
Can stdout be forced to print somewhere other than the screen?
What is the right type to use for boolean values in c?
Why doesn't C support function overloading?
How would you use the functions fseek(), freed(), fwrite() and ftell()?
What is the difference between single charater constant and string constant?
What are the storage classes in C?