Question

Write a PHP code that: 1- Creates an array that holds 10 random integer numbers between...

Write a PHP code that:

1-

Creates an array that holds 10 random integer numbers between 1 and 100.

2-

Moves all multiple of 3-numbers in the array that created in part-a into a new array.

3-

Moves all multiple of 5-numbers in the array that created in part-a into a new array.

4-

Find the maximum and the minimum multiple of 3-numbers, if exist.

5-

Find the maximum and the minimum multiple of 5-numbers, if exist.

6-

Prints the elements of the created arrays in part-1, part-2 and part-3.

7-

Prints the maximum and minimum multiple of 3-numbers.

8-

Prints the maximum and minimum multiple of 5-numbers.

9-

Prints a suitable message if no multiple of 3-numbers or multiple of 5-numbers are generated.

Homework Answers

Answer #1

PROGRAM::

<!DOCTYPE html>
<html>
<body>

<?php
function displayArray($a){
if(sizeof($a)==0)
{
echo "No elements";
return;
}
foreach (range(0, sizeof($a)-1, 1) as $index) {
echo $a[$index],"&nbsp";
}
}

function maxNumber($arr){
if(sizeof($arr)==0)
return 0;
$max=$arr[0];
foreach (range(1, sizeof($arr)-1, 1) as $index) {
if($arr[$index]>$max)
$max=$arr[$index];
}
return $max;
}

function minNumber($arr){
if(sizeof($arr)==0)
return 0;
$max=$arr[0];
foreach (range(1, sizeof($arr)-1, 1) as $index) {
if($arr[$index]<$max)
$max=$arr[$index];
}
return $max;
}
$a = array();
foreach (range(0, 10, 1) as $index) {
$a[$index]=rand(0, 100);
}
echo "Part 1: ";
displayArray($a);
echo "<br>";

$ThreeMulArray = array();
$FiveMulArray = array();
$threeIndex=0;
$fiveIndex=0;
foreach (range(0, 10, 1) as $index) {
if($a[$index]%3==0){
$ThreeMulArray[$threeIndex]=$a[$index];
$threeIndex+=1;
}else if(($a[$index]%5==0)){
$FiveMulArray[$fiveIndex]=$a[$index];
$fiveIndex+=1;
}
unset($a[$index]);
}

echo "Part 2: ";
displayArray($ThreeMulArray);
echo "<br>";

echo "Part 3: ";
displayArray($FiveMulArray);
echo "<br>";
  
echo "maximum in three multiples array: ";
$result=maxNumber($ThreeMulArray);
if($result)
echo $result;
else
echo "Does not exit";
echo "<br>";


echo "Minimum in three multiples array: ";
$result=minNumber($ThreeMulArray);
if($result)
echo $result;
else
echo "Does not exit";
echo "<br>";

echo "maximum in five multiples array: ";
$result=maxNumber($FiveMulArray);
if($result)
echo $result;
else
echo "Does not exit";
echo "<br>";
  
  
echo "Minimum in five multiples array: ";
$result=minNumber($FiveMulArray);
if($result)
echo $result;
else
echo "Does not exit";

?>


</body>
</html>

SCREENSHOTS::

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
The code segment in Listing 1, when completed and executed, creates nums, an uninitialized 4-integer array....
The code segment in Listing 1, when completed and executed, creates nums, an uninitialized 4-integer array. It stores 4 and 5 as the first and second elements, respectively, of the array. It adds the first and second elements of the array and stores their sum as the third element of the nums. It prints the third element of nums. It then adds the second and third elements of the array and stores their sum as the fourth element of nums....
Write a program in Java that creates an array of doubles. The array must have size...
Write a program in Java that creates an array of doubles. The array must have size 1000. Fill this array with random numbers between 0 and 1. Then compute and print the total value of all the elements of the array, the mean, the minimum, and the maximum. Filling the array with random numbers must be done by a method that you define and implement. Computing and printing the statistics must be done by another method, which again you must...
In java 1. Write a recursive algorithm to add all the elements of an array of...
In java 1. Write a recursive algorithm to add all the elements of an array of n elements 2. Write a recursive algorithm to get the minimum element of an array of n elements 3. Write a recursive algorithm to add the corresponding elements of two arrays (A and B) of n elements. Store the results in a third array C. 4. Write a recursive algorithm to get the maximum element of a binary tree 5. Write a recursive algorithm...
Write a java program that creates an integer array with 50 random values, prompts the user...
Write a java program that creates an integer array with 50 random values, prompts the user to enter the index of an element in the array between 0 and 49, then displays the corresponding element value. If the specified index is out of bounds, display an error message (e.g. “Out of Bounds”) and ask the user to enter another index. Use a while loop that will keep prompting the user until a valid input is received. To handle invalid inputs,...
1.) Generate an array of 10 random numbers between 1 - 100 2.) Copy the array...
1.) Generate an array of 10 random numbers between 1 - 100 2.) Copy the array to a temp array 3.) Call each of the methods to sort (bubble, selection, insertion, quick, merge), passing it the array 4.) In-between the calls, you are going to refresh the array to the original numbers. 5.) Inside of each sorting method, you are going to obtain the nanoseconds time, before and after the method Subtract the before time from the after time to...
Use C++ 1 a)Write a console program which creates an array of size 100 integers. Then...
Use C++ 1 a)Write a console program which creates an array of size 100 integers. Then use Fibonacci function Fib(n) to fill up the array with Fib(n) for n = 3 to n = 103: So this means the array looks like: { Fib(3), Fib(4), Fib(5), ...., Fib[102) }. For this part of assignment you should first write a recursive Fib(n) funcion, as was done in class.For testing, print out the 100 integers. 1 b) For second part of this...
Complete the following program. This program should do the following: 1. Creates a random integer in...
Complete the following program. This program should do the following: 1. Creates a random integer in the range 10 to 15 for variable: allThreads, to create a number of threads. 2. Creates a random integer for the size of an ArrayList: size. 3. Each thread obtains a smallest number of a segment of the array. To give qual sized segment to each thread we make the size of the array divisible by the number of threads: while(size%allThreads != 0)size++ 4....
Lottery The lottery game matches three different integer numbers between 1 and 10. Winning depends on...
Lottery The lottery game matches three different integer numbers between 1 and 10. Winning depends on how many matching numbers are provided by a player. The player provides three different integers between 1 and 10. If there is a match of all 3 numbers, the winning $ 1000. If there is a match with 2 numbers, the winning $ 10. If there is a match with 1 number, the winning $ 1. With no match, the winning is $0. Write...
Declare an integer array of size 10 with values initialized as follows. int intArray[] = {1,...
Declare an integer array of size 10 with values initialized as follows. int intArray[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; Compute each item of a new array of same size derived from the above array by: adding first item (intArray[0]) of the array with 3rd, 2nd with 4th, 3rd with 5th and so on. For the last-but-one item intArray[8], add it with first item and for the last item (intArray[9]) add it with 2nd item...
C program question: Write a small C program connect.c that: 1. Initializes an array id of...
C program question: Write a small C program connect.c that: 1. Initializes an array id of N elements with the value of the index of the array. 2. Reads from the keyboard or the command line a set of two integer numbers (p and q) until it encounters EOF or CTL - D 3. Given the two numbers, your program should connect them by going through the array and changing all the entries with the same name as p to...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT