Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Homework
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);
                }
            }
            Console.ReadLine();
 
        }
    }
}
 
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.
 
Sorry for the bad english
Posted 29-Jan-13 4:29am
Comments
richcb at 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: bad
good
Please Sign up or sign in to vote.

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
  Permalink  
v2
Comments
Transitional at 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 at 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);
}
}
Console.ReadLine();
 
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 at 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: bad
good
Please Sign up or sign in to vote.

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
  Permalink  
Comments
Matt T Heffron at 29-Jan-13 16:33pm
   
(See my note above about the remainder == 0)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 300
1 Sergey Alexandrovich Kryukov 176
2 PhilLenoir 164
3 Richard MacCutchan 160
4 Sharmanuj 146
0 Sergey Alexandrovich Kryukov 6,081
1 OriginalGriff 5,115
2 CPallini 2,473
3 Richard MacCutchan 1,597
4 Abhinav S 1,505


Advertise | Privacy | Mobile
Web04 | 2.8.140814.1 | Last Updated 29 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100