# Need help with homework

Page 1 of 1

## 12 Replies - 535 Views - Last Post: 16 October 2017 - 12:49 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=406909&amp;s=2964b96aa51206d8b08959b9e695fafa&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 bobs12345

• New D.I.C Head

Reputation: 0
• Posts: 7
• Joined: 15-October 17

# Need help with homework

Posted 15 October 2017 - 07:53 AM

Hi this is my homework (picture)
https://imgur.com/wz8cCy8
Homework asks that the user enters a number and then the paradigm is solved.
My struggle is that i cant find code the first numbers (1,1,2,6,24..) and its answers.
Code so far.
```            int a;

for (int i = 1; i <= a; i++)
{
{

Console.WriteLine("*"+i +"=");
}
}
```

This post has been edited by modi123_1: 15 October 2017 - 08:59 AM
Reason for edit:: In the future, please use the [code] tag button in the editor..

Is This A Good Question/Topic? 0

## Replies To: Need help with homework

### #2 ndc85430

• D.I.C Lover

Reputation: 587
• Posts: 2,466
• Joined: 13-June 14

## Re: Need help with homework

Posted 15 October 2017 - 08:00 AM

It's just the factorial of an integer n, n! = 1 x 2 x 3 x ... x n - 1 x n.

This post has been edited by ndc85430: 15 October 2017 - 08:01 AM

### #3 bobs12345

• New D.I.C Head

Reputation: 0
• Posts: 7
• Joined: 15-October 17

## Re: Need help with homework

Posted 15 October 2017 - 08:46 AM

ndc85430, on 15 October 2017 - 03:00 PM, said:

It's just the factorial of an integer n, n! = 1 x 2 x 3 x ... x n - 1 x n.

no idea how to make it work

### #4 modi123_1

• Suitor #2

Reputation: 13482
• Posts: 53,820
• Joined: 12-June 08

## Re: Need help with homework

Posted 15 October 2017 - 09:00 AM

What do you need in a factorial? The number to count to.. a variable to hold the results of some math.. and a way to count from 1 to some number.

### #5 bobs12345

• New D.I.C Head

Reputation: 0
• Posts: 7
• Joined: 15-October 17

## Re: Need help with homework

Posted 15 October 2017 - 09:09 AM

modi123_1, on 15 October 2017 - 04:00 PM, said:

What do you need in a factorial? The number to count to.. a variable to hold the results of some math.. and a way to count from 1 to some number.

Thanks for showing interset for helping.
I need exacly how is shown in picture.
Where it asks to user to write any number example :6
then it shows how factorial 6 is calculated.
1*1=1
1*2=2
2*3=6
6*4=24
24=5=120
120*6=720
I have no idea how to code first number and its answer.

### #6 modi123_1

• Suitor #2

Reputation: 13482
• Posts: 53,820
• Joined: 12-June 08

## Re: Need help with homework

Posted 15 October 2017 - 09:13 AM

Again.. it takes a bit of time to think out what you need. Variable to hold the input number, a loop that goes to that number, and a variable to hold the math results.

Which parts of that do you have done?

### #7 bobs12345

• New D.I.C Head

Reputation: 0
• Posts: 7
• Joined: 15-October 17

## Re: Need help with homework

Posted 15 October 2017 - 09:21 AM

modi123_1, on 15 October 2017 - 04:13 PM, said:

Again.. it takes a bit of time to think out what you need. Variable to hold the input number, a loop that goes to that number, and a variable to hold the math results.

Which parts of that do you have done?

i got part where user inputs number example: 6
like this using for loop
1
2
3
4
5
6

### #8 modi123_1

• Suitor #2

Reputation: 13482
• Posts: 53,820
• Joined: 12-June 08

## Re: Need help with homework

Posted 15 October 2017 - 09:27 AM

Okay.. then you need what? A variable created to hold the math you would be doing using the number in the loop control variable in the for loop.

### #9 bobs12345

• New D.I.C Head

Reputation: 0
• Posts: 7
• Joined: 15-October 17

## Re: Need help with homework

Posted 15 October 2017 - 09:32 AM

modi123_1, on 15 October 2017 - 04:27 PM, said:

Okay.. then you need what? A variable created to hold the math you would be doing using the number in the loop control variable in the for loop.

Yes.
i have tried
i*i
but then its
1*1=1
2*2=4... which is not that what is needed.

### #10 ndc85430

• D.I.C Lover

Reputation: 587
• Posts: 2,466
• Joined: 13-June 14

## Re: Need help with homework

Posted 15 October 2017 - 09:33 AM

That's not what the factorial of n is, though. It's the product of all the numbers from 1 to n, as above. Perhaps another way to think about it is like this:

n! = n x (n - 1)!,

where (n - 1)! = (n - 1) x (n - 2)!

and so on. For example:

2! = 2 x 1! = 2
3! = 3 x 2! = 3 x (2 x 1!) = 3 x 2 = 6

and so on.

This post has been edited by ndc85430: 16 October 2017 - 12:27 AM

### #11 tlhIn`toq

• Xamarin Cert. Dev.

Reputation: 6507
• Posts: 14,372
• Joined: 02-June 10

## Re: Need help with homework

Posted 15 October 2017 - 03:56 PM

If the OP doesn't understand the math portion (factorial) then they can't visualize how to code the steps they would do on paper.
There are countless math tutorial sites... videos on how to do factorials and so on.

But it might be best if you go talk to your teacher. Explain that you don't grasp the math, and thus don't know what you would need to code.

### #12 bobs12345

• New D.I.C Head

Reputation: 0
• Posts: 7
• Joined: 15-October 17

## Re: Need help with homework

Posted 16 October 2017 - 12:05 PM

tlhIn`toq, on 15 October 2017 - 10:56 PM, said:

If the OP doesn't understand the math portion (factorial) then they can't visualize how to code the steps they would do on paper.
There are countless math tutorial sites... videos on how to do factorials and so on.

But it might be best if you go talk to your teacher. Explain that you don't grasp the math, and thus don't know what you would need to code.

Thnaks for helping guys!!! i finally managed to make it work. Now i understand where was my problem.

### #13 bobs12345

• New D.I.C Head

Reputation: 0
• Posts: 7
• Joined: 15-October 17

## Re: Need help with homework

Posted 16 October 2017 - 12:49 PM

bobs12345, on 16 October 2017 - 07:05 PM, said:

tlhIn`toq, on 15 October 2017 - 10:56 PM, said:

If the OP doesn't understand the math portion (factorial) then they can't visualize how to code the steps they would do on paper.
There are countless math tutorial sites... videos on how to do factorials and so on.

But it might be best if you go talk to your teacher. Explain that you don't grasp the math, and thus don't know what you would need to code.

Thnaks for helping guys!!! i finally managed to make it work. Now i understand where was my problem. />/>/>

here is how the code look like
```int a;

int q = 1;

for (int i = 1; i <= a; i++)
{

Console.Write(q+"*"+i +"=");
Console.WriteLine(q = q * i);

}
```

This post has been edited by modi123_1: 16 October 2017 - 12:52 PM
Reason for edit:: Here's how the code looks with code tags.. ;)