1.factorial Program in C Sharp Using For Loop
1.factorial Program in C Sharp Using For Loop
factorial program in c sharp using for loop This program calculate factorial of given number using for loop in C#. for example this program calculate factorial of 4 and give answer 24. you can try this program for different numbers. instead of for loop you can also use other loops like while and do while loop or you can go for recursive functions.
using System; using System.Text; using System.Collections; using System.Data; namespace Console_App { public class clsFactorial { public static void Main() { try { Console.WriteLine("The factorial of 4 is: {0}\n", Factorial(4)); } catch(Exception ex) { //handle exception here } Console.ReadLine(); } static long Factorial(long number) { long FinalNumber = 1; for (int i = 1; i <= number; i++) { FinalNumber = FinalNumber * i;
} return FinalNumber; } } }
377
class Program { static void Main() { Console.WriteLine(StringHelper.ReverseString("framework")); Console.WriteLine(StringHelper.ReverseString("samuel")); Console.WriteLine(StringHelper.ReverseString("example string")); } } Output krowemarf leumas gnirts elpmaxe