# DIVIDING USING FOR LOOP AND WHILE LOOP

Page 1 of 1

## 3 Replies - 9785 Views - Last Post: 09 August 2007 - 08:30 AMRate 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=31434&amp;s=88df2e6e174aa93044b623e0e9c9a9bd&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 dianenacario

• New D.I.C Head

Reputation: 0
• Posts: 5
• Joined: 08-August 07

# DIVIDING USING FOR LOOP AND WHILE LOOP

Posted 09 August 2007 - 12:15 AM

int[] Divide(int divisor, int dividend)
{
int remainder = dividend;
int quotient = 0;

while (remainder >= divisor)
{
remainder -= divisor;
quotient++;
}

return new int[] { quotient, remainder };
}

[b] i am trying to do a divison program..
i should not use " / or %"
i should only use a while loop or a for loop.

i wanted it to be like this,

output of program: any number / any number = quotient
input dividend: dividend
input divisor: divisor
quotient: quotient
remainder: if there is a remainder
[i]

This post has been edited by dianenacario: 09 August 2007 - 12:27 AM

Is This A Good Question/Topic? 0

## Replies To: DIVIDING USING FOR LOOP AND WHILE LOOP

### #2 PsychoCoder

Reputation: 1654
• Posts: 19,853
• Joined: 26-July 07

## Re: DIVIDING USING FOR LOOP AND WHILE LOOP

Posted 09 August 2007 - 12:19 AM

Are you getting errors? If so what are they? We need more than "this don't work", how is it NOT working, what is it doing? Please provide a better explanation

### #3 dianenacario

• New D.I.C Head

Reputation: 0
• Posts: 5
• Joined: 08-August 07

## Re: DIVIDING USING FOR LOOP AND WHILE LOOP

Posted 09 August 2007 - 12:38 AM

dianenacario, on 9 Aug, 2007 - 12:15 AM, said:

int[] Divide(int divisor, int dividend)
{
int remainder = dividend;
int quotient = 0;

while (remainder >= divisor)
{
remainder -= divisor;
quotient++;
}

return new int[] { quotient, remainder };
}

[b] i am trying to do a divison program..
i should not use " / or %"
i should only use a while loop or a for loop.

i wanted it to be like this,

output of program: any number / any number = quotient
input dividend: dividend
input divisor: divisor
quotient: quotient
remainder: if there is a remainder
[i]

Im not receiving any error message but nothing appears when i start the program.
do you have any better suggestion on how i can do a division program using a for loop or while loop? im not suppose to use "/ and %"..

Im not receiving any error message but nothing appears when i start the program.
do you have any better suggestion on how i can do a division program using a for loop or while loop? im not suppose to use "/ and %"..

This post has been edited by dianenacario: 09 August 2007 - 12:40 AM

### #4 csmanoj

Reputation: 11
• Posts: 150
• Joined: 06-August 07

## Re: DIVIDING USING FOR LOOP AND WHILE LOOP

Posted 09 August 2007 - 08:30 AM

I put your method in my program like so...

```using System;

namespace csmanoj
{
class Division
{
public static void Main()
{
int[] answer = new int[2];

answer = Divide(8, 50);
}

public static int[] Divide(int divisor, int dividend)
{
int remainder = dividend;
int quotient = 0;

while (remainder >= divisor)
{
remainder -= divisor;
quotient++;
}
return new int[] {quotient, remainder};
}
}
}
```

And it worked. I got "6, 2" as output. I'm new to C# too so can't give you any explanation. But see if it strikes a chord for you.

This post has been edited by csmanoj: 09 August 2007 - 11:53 AM