C
C#12mo ago
RANI

hello how do i make console print the Factorial for num1

help
5 Replies
RANI
RANIOP12mo ago
namespace ConsoleApp5 { class Program { static void Main (string[] args) { Console.WriteLine("enter a Positive number "); int num1 = int.Parse(Console.ReadLine());
} } } code so far how do i make the Factorial dont write the code just lmk how do i do that
SinFluxx
SinFluxx12mo ago
is this some sort of task that you've got with instructions to do it a specific way at all?
RANI
RANIOP12mo ago
ye i got instructions Write a program that calculates the sum of the first n positive integers, where n is a user-entered positive integer. For example for n = 5 the program will print 1+2+3+4+5
SinFluxx
SinFluxx12mo ago
Have you used recursion before?
RANI
RANIOP12mo ago
i got it thanks. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp5 { class Program { static void Main(string[] args) { Console.WriteLine("enter a Positive number "); int num1 = int.Parse(Console.ReadLine());
while (num1 > 0) { for (int i = num1 - 1; i > 0; i--) { num1 += i; } Console.WriteLine("Factorial = {1}\n", num1, num1); num1--; Console.ReadLine(); } } } }
Want results from more Discord servers?
Add your server