Jump to content

C# Hw


progamerz

Recommended Posts

  On 10/26/2017 at 4:03 PM, 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.

Expand  

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

Solution found, Request close

Link to comment
Share on other sites

  On 10/26/2017 at 3:57 PM, 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? 

Expand  

:???:

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

  On 10/26/2017 at 5:26 PM, 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

Expand  

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

  On 10/26/2017 at 5:41 PM, 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.

Expand  
  On 10/26/2017 at 5:38 PM, Prolax said:

Just an easy for loop..

Expand  

 

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...