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
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...
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...
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...
Write a code in c++ using linear insertion following the steps below. Comment your work. 1....
Write a code in c++ using linear insertion following the steps below. Comment your work. 1.    Ask the user for the name of a file containing data. If it does not exist, the program should display an error, then ask for a new file name. Entering an asterisk (*) as the first and only character on a line should terminate the program. 2.     You can use a statically-allocated one-dimensional array of doubles for this with length 100. You...
JAVA please Arrays are a very powerful data structure with which you must become very familiar....
JAVA please Arrays are a very powerful data structure with which you must become very familiar. Arrays hold more than one object. The objects must be of the same type. If the array is an integer array then all the objects in the array must be integers. The object in the array is associated with an integer index which can be used to locate the object. The first object of the array has index 0. There are many problems where...
Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the...
Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the program title and programmer’s name. Then get the user’s name, and greet the user. • Prompt the user to enter the number of Fibonacci terms to be displayed. Advise the user to enter an integer in the range [1 .. 46]. • Get and validate the user input (n). • Calculate and display all of the Fibonacci numbers up to and including the nth...
[Java] I'm not sure how to implement the code. Please check my code at the bottom....
[Java] I'm not sure how to implement the code. Please check my code at the bottom. In this problem you will write several static methods to work with arrays and ArrayLists. Remember that a static method does not work on the instance variables of the class. All the data needed is provided in the parameters. Call the class Util. Notice how the methods are invoked in UtilTester. public static int min(int[] array) gets the minimum value in the array public...
Use Python to Complete the following on a single text file and submit your code and...
Use Python to Complete the following on a single text file and submit your code and your output as separate documents. For each problem create the necessary list objects and write code to perform the following examples: Sum all the items in a list. Multiply all the items in a list. Get the largest number from a list. Get the smallest number from a list. Remove duplicates from a list. Check a list is empty or not. Clone or copy...
Complete this in C++ and explain what is being done. 1      Introduction The functions in the...
Complete this in C++ and explain what is being done. 1      Introduction The functions in the following subsections can all go in one big file called pointerpractice.cpp. 1.1     Basics Write a function, int square 1(int∗ p), that takes a pointer to an int and returns the square of the int that it points to. Write a function, void square 2(int∗ p), that takes a pointer to an int and replaces that int (the one pointed to by p) with its...