12 Replies - 535 Views - Last Post: 16 October 2017 - 12:49 PM Rate Topic: -----

#1 bobs12345  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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;
            
            Console.WriteLine("ievadiet skaitli");
            a=Convert.ToInt32(Console.ReadLine());
           
            for (int i = 1; i <= a; i++)
            {
                {
                    
                    Console.WriteLine("*"+i +"="); 
                }
            }
:code:

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  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 587
  • View blog
  • 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

Was This Post Helpful? 0
  • +
  • -

#3 bobs12345  Icon User is offline

  • New D.I.C Head

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

Re: Need help with homework

Posted 15 October 2017 - 08:46 AM

View Postndc85430, 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
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13482
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#5 bobs12345  Icon User is offline

  • New D.I.C Head

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

Re: Need help with homework

Posted 15 October 2017 - 09:09 AM

View Postmodi123_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.
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13482
  • View blog
  • 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?
Was This Post Helpful? 0
  • +
  • -

#7 bobs12345  Icon User is offline

  • New D.I.C Head

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

Re: Need help with homework

Posted 15 October 2017 - 09:21 AM

View Postmodi123_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
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13482
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#9 bobs12345  Icon User is offline

  • New D.I.C Head

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

Re: Need help with homework

Posted 15 October 2017 - 09:32 AM

View Postmodi123_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.
Was This Post Helpful? 0
  • +
  • -

#10 ndc85430  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 587
  • View blog
  • 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

Was This Post Helpful? 0
  • +
  • -

#11 tlhIn`toq  Icon User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6507
  • View blog
  • 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.
https://www.google.c...=utf-8&oe=utf-8

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.
Was This Post Helpful? 0
  • +
  • -

#12 bobs12345  Icon User is offline

  • New D.I.C Head

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

Re: Need help with homework

Posted 16 October 2017 - 12:05 PM

View PosttlhIn`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.
https://www.google.c...=utf-8&oe=utf-8

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. :)
Was This Post Helpful? 0
  • +
  • -

#13 bobs12345  Icon User is offline

  • New D.I.C Head

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

Re: Need help with homework

Posted 16 October 2017 - 12:49 PM

View Postbobs12345, on 16 October 2017 - 07:05 PM, said:

View PosttlhIn`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.
https://www.google.c...=utf-8&oe=utf-8

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;
             
            
            
            Console.WriteLine("ievadiet skaitli");
            a=Convert.ToInt32(Console.ReadLine());

            

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

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

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

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1