12,291,471 members (62,673 online)
Rate this:
See more:
Hello.

This is a homework so don't give me the answer.

IM going to do a program that look in to every numerator and denominator from 1 -100 in both numerator and denominatorf the quotient is = 5 then the numerator and denominatorf will be typed out on the screen.

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

}
}
}```

this is what i have done. Only geting to show denominatorf the quotient to 1- 100.
I know that i need to put in a new int and then count out the = 5 in the if but i dont really know how to do it can any one help me whit it.

Posted 29-Jan-13 4:29am
richcb 29-Jan-13 10:45am

You are looping through all 100 "num2" for every "num1". That logic will not work. Hope that helps.

Rate this:

## Solution 2

the program going to loop through 1-100 100-1 and every time the quotient is = 5 the two number and = 5 going to show on the screen for example 10/2 and that is going on the console screen
v2
Transitional 29-Jan-13 10:50am

if i understand what you are trying to say. than you should use %5

eq if 25 % 5 is zero than show on screen
Tommy116 29-Jan-13 11:01am

int num1, num2, sum;
for (num1 = 1; num1 <= 101; num1++)
{
for (num2 = 1; num2 <= 101; num2++)
{
if ()
Console.WriteLine(sum);
}
}

i have tried a lot of diffrent stuff but not the right one of course becous it only com up that i need to use a bool in this but i beliwe you can do this white out a bool. like this under the if statment sum = num1 / num2 and then change the int sum = 5; but what im i going to put in to the if() that is what a troubling me
Matt T Heffron 29-Jan-13 16:32pm

First of all this is looping through 1-101 (not 100).
The next question is: must the quotient be 5 AND the remainder == 0?
(I'd guess that is what you want.)
So use the % operator to get the remainder, OR use the Math.DivRem(...) method to get both quotient and remainder at the same time.
I'd also suggest renaming the variables to more meaningful names: numerator, denominator, quotient, remainder, ...
Rate this:

## Solution 3

i tryd to put in
```if (num1 / num2 == 5)
Console.WriteLine(num1+"/"+num2);```

put it show only one side of it and it dont showe the right answer only on the 2 first and then it do what it whant
Matt T Heffron 29-Jan-13 16:33pm

(See my note above about the remainder == 0)

Top Experts
Last 24hrsThis month
 KARTHIK Bangalore 355 OriginalGriff 280 Sergey Alexandrovich Kryukov 173 ppolymorphe 155 Mehdi Gholam 144
 OriginalGriff 8,110 ppolymorphe 4,987 CHill60 4,940 Sergey Alexandrovich Kryukov 4,353 KARTHIK Bangalore 4,347