2 Replies - 237 Views - Last Post: 29 January 2013 - 11:24 AM Rate Topic: -----

#1 Johan113  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 17-January 12

quotient in loop

Posted 29 January 2013 - 11:06 AM

hello

this is a homework so please dont give me the answer to the problem.

            int num1, num2;
            for (num1 = 1; num1 <= 101; num1++)
            {
                for (num2 = 1; num2 <= 101; num2++)
                {
                    if (num1 / num2 == 5)
                        Console.WriteLine(num1 + "/" + num2);
                }
            }
            Console.ReadLine();


this is what i have so far. the 2 numbers that com up first is right but then its relly get wrong. I want it to be every time the 2 numbers have the quotient of 5 the 2 numbers will com up on the screen. like if 10/2 = 5 then the 10/5 will com up.

sorry for my bad english

Is This A Good Question/Topic? 0
  • +

Replies To: quotient in loop

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3479
  • View blog
  • Posts: 10,725
  • Joined: 05-May 12

Re: quotient in loop

Posted 29 January 2013 - 11:20 AM

What do you mean by "but then its really get wrong"? The code seems to be doing exactly what you told it to do.

Remember that when you divide one integer by another integer, you get an integer result. So 11 / 2 == 5. Perhaps you are looking for the cases when the remainder is zero, and when the quotient is 5. In that case you'll probably want to use the modulus (%) operator as well.

This post has been edited by Skydiver: 29 January 2013 - 11:21 AM

Was This Post Helpful? 1
  • +
  • -

#3 Johan113  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 17-January 12

Re: quotient in loop

Posted 29 January 2013 - 11:24 AM

i fix it
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1