Diese Präsentation wurde erfolgreich gemeldet.
Die SlideShare-Präsentation wird heruntergeladen. ×

Please help me with my PHP programming assignment- 1- Write a PHP prog.docx

Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Nächste SlideShare
php 1
php 1
Wird geladen in …3
×

Hier ansehen

1 von 3 Anzeige

Please help me with my PHP programming assignment- 1- Write a PHP prog.docx

Herunterladen, um offline zu lesen

Please help me with my PHP programming assignment.
1- Write a PHP program that goes through all integers between 1 and 100
(exclusive) and displays each even number on a separate line.

2- Re-write the program in question 1 but this time use a function to go through the
numbers and display them.
Note: Question one has been solved, please give me feedbacks regard of question two. Please copy and paste your code after you finish.
Solution
/* main.php */
/* PHP program that goes through all integers between 1 and 100 (exclusive) and displays each even number on a separate line. */
<html>
<head>
<title>PHP Program</title>
</head>
<body>
<?php
for ($i=1; $i<=100; $i++)
{
if($i%2==0)
echo $i.\"<br/>\";
}
?>
</body>
</html>
/* main2.php */
/* function to go through the numbers and display them. */
<html>
<head>
<title>PHP Function</title>
</head>
<body>
<?php
/* Defining a PHP Function */
function displayNumbers() {
for ($i=1; $i<=100; $i++)
{
if($i%2==0)
echo $i.\"<br/>\";
}
}
/* Calling a PHP Function */
displayNumbers();
?>
</body>
</html>
/* output
2
4
6
8
10
12
14
16
18
20
22
24
26
28
30
32
34
36
38
40
42
44
46
48
50
52
54
56
58
60
62
64
66
68
70
72
74
76
78
80
82
84
86
88
90
92
94
96
98
100
*/
.

Please help me with my PHP programming assignment.
1- Write a PHP program that goes through all integers between 1 and 100
(exclusive) and displays each even number on a separate line.

2- Re-write the program in question 1 but this time use a function to go through the
numbers and display them.
Note: Question one has been solved, please give me feedbacks regard of question two. Please copy and paste your code after you finish.
Solution
/* main.php */
/* PHP program that goes through all integers between 1 and 100 (exclusive) and displays each even number on a separate line. */
<html>
<head>
<title>PHP Program</title>
</head>
<body>
<?php
for ($i=1; $i<=100; $i++)
{
if($i%2==0)
echo $i.\"<br/>\";
}
?>
</body>
</html>
/* main2.php */
/* function to go through the numbers and display them. */
<html>
<head>
<title>PHP Function</title>
</head>
<body>
<?php
/* Defining a PHP Function */
function displayNumbers() {
for ($i=1; $i<=100; $i++)
{
if($i%2==0)
echo $i.\"<br/>\";
}
}
/* Calling a PHP Function */
displayNumbers();
?>
</body>
</html>
/* output
2
4
6
8
10
12
14
16
18
20
22
24
26
28
30
32
34
36
38
40
42
44
46
48
50
52
54
56
58
60
62
64
66
68
70
72
74
76
78
80
82
84
86
88
90
92
94
96
98
100
*/
.

Anzeige
Anzeige

Weitere Verwandte Inhalte

Ähnlich wie Please help me with my PHP programming assignment- 1- Write a PHP prog.docx (20)

Weitere von rtodd19 (20)

Anzeige

Aktuellste (20)

Please help me with my PHP programming assignment- 1- Write a PHP prog.docx

  1. 1. Please help me with my PHP programming assignment. 1- Write a PHP program that goes through all integers between 1 and 100 (exclusive) and displays each even number on a separate line. 2- Re-write the program in question 1 but this time use a function to go through the numbers and display them. Note: Question one has been solved, please give me feedbacks regard of question two. Please copy and paste your code after you finish. Solution /* main.php */ /* PHP program that goes through all integers between 1 and 100 (exclusive) and displays each even number on a separate line. */ <html> <head> <title>PHP Program</title> </head> <body> <?php for ($i=1; $i<=100; $i++) { if($i%2==0) echo $i."<br/>"; } ?> </body> </html> /* main2.php */ /* function to go through the numbers and display them. */
  2. 2. <html> <head> <title>PHP Function</title> </head> <body> <?php /* Defining a PHP Function */ function displayNumbers() { for ($i=1; $i<=100; $i++) { if($i%2==0) echo $i."<br/>"; } } /* Calling a PHP Function */ displayNumbers(); ?> </body> </html> /* output 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48
  3. 3. 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 */

×