Create a script using a for loop to add all the integers between 0 and 30 and display the sum

  • برمجة بي اتش بي

Create a script using a for loop to add all the integers between 0 and 30 and display the sum

الأجوبة

<?php
$sum = 0;
for($x=1; $x<=30; $x++)
{
$sum +=$x;
}
echo "The sum of the numbers 0 to 30 is $sum"."\n";
?>

Sample Output:

The sum of the numbers 0 to 30 is 465
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...