Computer Science, asked by ririrora, 4 months ago

Write a program that receives a natural number from the input and prints the factorial. (Using for loop) C#

Answers

Answered by anindyaadhikari13
2

Solution:

The given c‎ode is written in C#.

using System;  

namespace SoloLearn{

public class Program{

 public static void Main(string[] args){

  int i,number, factorial=1;

           Console.WriteLine("Enter a number: ");

           number=int.Parse(Console.ReadLine());

           for(i=2;i<=number;i++)

               factorial*=i;

           Console.WriteLine("Factorial is: "+factorial);

 }

}

}

Logic:

  • Initialise factorial = 1.
  • Take the number as input.
  • Loop from i = 2 to number.
  • Multiply each values of 'i' and store the result in factorial variable.
  • Display the value of factorial.

See the attachment for output.

Attachments:
Answered by Anonymous
0

Answer:

Solution:

The given c‎ode is written in C#.

using System;    

namespace SoloLearn

public class Program

public static void Main(string[] args){

int i,number, factorial=1;

Console.WriteLine("Enter a number: ");

number=int.Parse(Console.ReadLine());

for(i=2;i<=number;i++)

 factorial*=i;

Console.WriteLine("Factorial is: "+factorial);

Logic:

Initialise factorial = 1.

Take the number as input.

Loop from i = 2 to number.

Multiply each values of 'i' and store the result in factorial variable.

Display the value of factorial.

Explanation:

Thanks..

Plz mark as brainliest..

Have A Nice Day..!

Similar questions