Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7833295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:38:56+00:00 2026-06-02T12:38:56+00:00

Im studying for finals and i came across this question: write a PHP script

  • 0

Im studying for finals and i came across this question:

write a PHP script which reads a positive integer
and displays the sum, the number, sum N*N and N!
for example n=6 will display sum= 1,3,6,10,15,21
and N*N = 1,4,9,16,25,36
N!=1,2,6,24,120,720.

i have managed to do the number that’s it, i have researched, you can use the inbuilt factorial and sum method, i have tried but i get empty pages when i output it.

here is my code so far:

<html>
   <body>
      <form action="values.php" method="post" >
         num:<input type="text" name="num" size ="5"/>
         <input type = "submit" value = "Submit number" />

      <table border = "2">
        <th> Number </th>
        <th> Sum </th>
        <th> N*N </th>
        <th> N! </th>

        </tr>
     <?php
        $num=$_POST["num"];
        if ($num==0)
            $num="";
        else
        {
           $sum=0;
           for($i=0; $i<=$num; $i++){
           $sum=$sum+$i;
        }
     }


          for ($number = 1; $number <=6; $number++)
          {
            $total=0;
            $num=(int)$_POST['num'];
            $total=$total+$num;

               $root = sqrt($number);
               $sum =($number*$total);
               $ntn =($number*($total*$total));
               $fact =($number-1);

               print("
               <tr align = 'center'>
               <td> $number </td>
               <td> $sum </td>
               <td>$ntn </td>
               <td>$fact</td>
               </tr>\n");
          }
    ?>
</table>


</body>

Any help would be appreciated.

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T12:38:58+00:00Added an answer on June 2, 2026 at 12:38 pm

    Working code:

    You don’t seem to have understood the question. The “sum” column was to have “sum of all numbers up to i”, where i ranged from 0 to $num.

    N*N was to hold “squares of i”, and the last one held “factorial of i”.

    <html>
       <body>
          <form action="values.php" method="post" >
             num:<input type="text" name="num" size ="5"/>
             <input type = "submit" value = "Submit number" />
    
          <table border = "2">
            <th> Number </th>
            <th> Sum </th>
            <th> N*N </th>
            <th> N! </th>
    
            </tr>
         <?php
            $num=$_POST["num"];
            if ($num==0){
                $num="";
         }
    
    $sum=0;
    $fact=1;
              for ($number = 1; $number <=$num; $number++)
              {
    
               $sum=$sum+$number;
                   $ntn =$number*$number;
                   $fact =$number*$fact;
    
                   print("
                   <tr align = 'center'>
                   <td> $number </td>
                   <td> $sum </td>
                   <td>$ntn </td>
                   <td>$fact</td>
                   </tr>\n");
              }
        ?>
    </table>
    
    
    </body>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm studying for finals and i came across this question: Write a php script
I was studying for my finals and I came across this question: write the
I'm a computer science undergrad and I'm just studying for finals. I came across
I was studying method overriding in Java when ai came across the this keyword.
I was studying an open source code where I came across the following line
studying some sample code from an iOS programming course (cs193p fall2010) i came across
im studying for my programming final exam. I have to write a program which
In studying actionscript 3's graphics class, I've come across the undocumented drawRoundRectComplex() method. It's
After studying TCP/UDP difference all week, I just can't decide which to use. I
I'm studying for a final exam and I stumbled upon a curious question that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.