Write C# program to find factorial of any number


Introduction

I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability..


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. public class csharpExercise
  7. {
  8. static void Main(string[] args)
  9. {
  10. int num,i;
  11. long fact=1;
  12.  
  13. // Reading number
  14. Console.Write("Enter any number to calculate factorial: ");
  15. num = Convert.ToInt32(Console.ReadLine());
  16. fact = 1;
  17. i = 1;
  18.  
  19. //Run loop from 1 to number entered by user
  20. while(i <= num)
  21. {
  22. fact = fact * i;
  23. i++;
  24. }
  25.  
  26. Console.Write("Factorial of : "+ num +" is " + fact);
  27.  
  28. Console.ReadLine();
  29. }
  30. }

Result

C# language techstudy

     





Related Topics




Popular Posts