Jump to content

multiplication in a loop


adamgonge

Recommended Posts

im working on a problem that involves a loop that goes to 64 with each time the number is doubling itself so it would be 1,2,4,8,16.. I dont know how to do it .

I currently have this code which is wrong it just ends up taking 64*2 but i dont know how else to set this up. 

 

 

 
<html>
 <head>
  <title>PHP Test</title>
 </head>
 <body>
 <?php echo '<p>Multiplication test</p>'; ?>
<?php
 
$total = 0;
$even = 0;
 
for ( $x = 1; $x <= 64; $x++ ) {
 
    $sum = 1+$x*2;
 
  }
 
echo "The total sum: ".$sum."<br />";
 
?>
 

Link to comment
Share on other sites

i changed the equation but now it just ends up with 64squared whereas i think i need the sum of all the squares.

 

new

<html>
 <head>
  <title>PHP Test</title>
 </head>
 <body>
 <?php echo '<p>Multiplication test</p>'; ?>
<?php
 
$total = 0;
$even = 0;
 
for ( $x = 0; $x < 64; $x++ ) {
 
    $sum =($x+1*2)*$x;
 
  }
 
echo "The total sum: ".$sum."<br />";
 
?>
 
 
</body>
</html>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.