Successfully reported this slideshow.
Your SlideShare is downloading. ×

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

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Upcoming SlideShare
php 1
php 1
Loading in …3
×

Check these out next

1 of 3 Ad

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

Download to read offline

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
*/
.

Advertisement
Advertisement

More Related Content

Similar to Please help me with my PHP programming assignment- 1- Write a PHP prog.docx (20)

More from rtodd19 (20)

Advertisement

Recently uploaded (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 */

×