Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » Php - Finding the biggest number
Closed Thread
Old 11-26-2005, 09:56 AM   #1 (permalink)
 
True Techie

Join Date: Apr 2005

Posts: 110

Murdoc

Default Php - Finding the biggest number

Hi, I'm making a script so that it can read in a file that has 2 numbers each line and break it down so they become usable data. I named n1 (number 1) and n2 (number2).

If I have a set of numbers:
eg:
N1 N2
12 4
14 2
2 5

and I wanted the computer to subtract N2 and N1 starting from the bigggest number (in this case, 14 and 2) how can I get it to determine which number is the biggest and subtract it with N2?

<!--------------MY PHP SCRIPT SO FAR-------------!>
<?php
$fp = fopen ("read.txt","r");
for ($y = 0; $y <=5; $y++) # Do this program 5 times
{
$rd = trim(fgets($fp,100));#the number that determines how many times file needs to be read
for ($x = 0; $x < $rd; $x++)
{
$fr = gets($fp,256); #reading the individual numbers
list ($n1,$n2) = explode (" ",$fr);
$An1 [$x] = $n1;#breaking down into an array for sorting and search
$An2 [$x] = $n2;# n2 array
rsort ($An1);
echo "
".$An1 [$x];
}
}
fclose($fp);
?>

<!-------------------TXT FILE CONTAINING DATA--------------!>
2
2 2
3 4
3
3 3
4 5
1 2
4
5 7
8 10
20 10
14 6
5
60 12
10 4
6 2
12 2
11 7
6
14 2
16 8
45 9
15 5
24 6
27 3
Murdoc is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On