In mathematics the notation n! represents the factorial of the nonnegative integ
ID: 3550488 • Letter: I
Question
In mathematics the notation n! represents the factorial of the nonnegative integer n. The factorial of a number is the product of all the nonnegative integers from 1 up through the number provided. For Example:
4! = 4 x 3 x 2 x 1 = 24
7! = 7 x 6 x 5 x 4 x 3 x 2 x 1 = 5,040
Create a loop structure to calculate and display the factorial of the larger number provided by the user.
What if these were test scores? Calculate the average of the two numbers provided. Determine the letter grade associated with the average (A = 90-100, B = 80-89, etc). Display a message to the user informing them of the letter grade they would have earned if the values provided were test scores.
Explanation / Answer
input.html
==========
<html>
<head>
<title>Even or Odd</title>
</head>
<body>
<form name="input" action="form1.php" method="post">
Value 1: <input type="text" name="value1"> <br>
Value 2: <input type="text" name="value2">
<input type="submit" value="Submit">
</form>
</body>
</html>
form1.php
==============
<?php
$val1 = $_POST['value1'];
$val2 = $_POST['value2'];
ini_set("precision", 3);
if(is_numeric($val1) && is_numeric($val2) && $val1 >= 0 && $val1 <= 100 && $val2 >= 0 && $val2 <= 100){
$smaller = $val1;
$larger = $val2;
if($val1 < $val2){
echo $val1, " is lesser than ", $val2, "<br>";
}
else if($val1 == $val2){
echo $val1, " is equal to ", $val2, "<br>";
}
else if($val1 > $val2){
$larger = $val1;
$smaller = $val2;
echo $val1, " is greater than ", $val2, "<br>";
}
echo "Printing factorial of the larger numbers.<br>";
$product = 1;
for ($i = 1; $i < $larger; $i++) {
$product *= $i;
}
echo $product, "<br>";
echo "Printing average.<br>";
$average = (float)($smaller+$larger)/2;
echo $average, "<br>";
echo "Printing grade.<br>";
if($average >= 90 && $average <= 100){
echo "A<br>";
}
else if($average >= 80 && $average < 90){
echo "B<br>";
}
else if($average >= 70 && $average < 80){
echo "C<br>";
}
else if($average >= 60 && $average < 70){
echo "D<br>";
}
else if($average >= 50 && $average < 60){
echo "E<br>";
}
else if($average >= 40 && $average < 50){
echo "F<br>";
}
else{
echo "Fail<br>";
}
}
else{
echo "Enter numeric numbers.";
}
?>
Adjust the grade boundaries as needed.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.