This code to PHP, help me, please!

General discussions related to php

Moderators: macek, egami, gesf

eduardouseredu
New php-forum User
New php-forum User
Posts: 1
Joined: Sat Apr 05, 2014 3:54 pm

This code to PHP, help me, please!

Postby eduardouseredu » Sat Apr 05, 2014 4:00 pm

Hi :)

I have this code in C language:

Code: Select all

    scanf("%d", &n);

       for (k = 1; k <= n; k = k + 1)
      {
         y = 2 * k;
         printf("\n%d", y);
      }


and I want to pass it to php

I write in PHP:

HTML

Code: Select all

<html>
   <body>
   <head>
   </head>
</head>
      <form action="ss.php" method="get">
      Digite um limite: <input type="text" name="n">
      <input type="submit" value="Submit">
      </form>
   </body>
</html>


PHP

Code: Select all

<?php
$y = $_GET['n'];

for ($i = 1; $i <= $y; $i++)
   {
       $y = (2 * $i) + 1;
       echo $y;
   }
?>


But have some errors, and I don't know how to fix them. Please help.

adicooldude
New php-forum User
New php-forum User
Posts: 10
Joined: Mon Apr 07, 2014 2:26 am

Re: This code to PHP, help me, please!

Postby adicooldude » Mon Apr 07, 2014 3:06 am

hi, can you provide those errors, it helps in solving the issue.

adicooldude
New php-forum User
New php-forum User
Posts: 10
Joined: Mon Apr 07, 2014 2:26 am

Re: This code to PHP, help me, please!

Postby adicooldude » Mon Apr 07, 2014 3:16 am

this works.

Code: Select all

<?php
$n = $_GET ['n'];
for($i = 1; $i <= $n; $i ++) {
   $y = (2 * $i) + 1;
   echo $y . '<br>';
}
?>


Return to “PHP General”

Who is online

Users browsing this forum: No registered users and 1 guest