Solution:
Pseudo Code:
- Initialize variable "num" to 1
- Initialize variable "factorial" to 1
- Print message on console to ask user for a number to know its factorial
- Read user's input and convert to Integer and store that input into variable "num" that is necessary for factorial calculation
- Start While loop till variable "num" value is grater then 1 (because initial value would be the user's input number)
- In each while loop add the product of "factorial" and "number" into "factorial"
- In each while after adding the factorial value , reduce the variable "num" by 1 so that once variable "num" value would reach to 1 then while loop will end.
- Print the variable "factorial" on console to show the calculated factorial..
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
int num, factorial = 1;
Console.WriteLine("please
enter the num to whom u want to know the
factorial");
num = Convert.ToInt32(Console.ReadLine());
while (num > 1)
{
factorial = factorial * num;
num = num - 1;
}
Console.WriteLine("the factorial of the num is {0}",
factorial);
}
}
}