Jump to content

C# Hw


progamerz

Recommended Posts

14 minutes ago, Shaft said:

int numberIn = Convert.ToInt32(Console.ReadLine());
int result = 1;
for(int i = numberIn; i > 0; i--;){
    result = result * i;
}
Console.WriteLine(numberIn + "!=" + result);

That should work i think.

Thanks appreciate it :) i didn't understand the question thats why

Solution found, Request close

Link to comment
Share on other sites

1 hour ago, progamerz said:

Q- Write a program and ask the user to enter a number. Compute the factorial of the number and print it on the console.
For example, if the user enters 5, the program should calculate 5 x 4 x 3 x 2 x 1 and display it as 5 ! = 120.

Can someone help me in this? :D

@The Hero of Time maybe? 

:???:

You could have Googled that and found a million examples, it's an extremely common question.

Either way you should have been able to figure it out, especially if you're scripter Juan.

Idk how you could not understand that question, it's a fookin for loop bro.

Time to start expanding your brain fam.

Although the for loop method is preferred, it can also be done recursively:

int Factorial(int i)
{
    if (i <= 1)
        return 1;
    return i * Factorial(i - 1);
}
Edited by Explv
Link to comment
Share on other sites

2 minutes ago, Explv said:

:???:

You could have Googled that and found a million examples, it's an extremely common question.

Either way you should have been able to figure it out, especially if you're scripter Juan.

Idk how you could not understand that question, it's a fookin for loop bro.

Time to start expanding your brain fam

the factorial didn't make sense for me lol, unless i knew the question wanted like if i entered 10, it will multiply it with all number less than 10 lol 

Link to comment
Share on other sites

13 minutes ago, Shaft said:

Considering you're a scripter you and u stating the equation in the question you really should have known how to do it...

Also your welcome.

17 minutes ago, Prolax said:

Just an easy for loop..

 

If i am "scripter" doesn't mean i am an expert in math, i have done already 4 exercices before this using "for" loop lol

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...