43.8k views
2 votes
Write the program code to find the cube of numbers from 1-5. Also do the dry run by using the trace table. (Javascript)

1 Answer

3 votes

Answer:

Following are the JavaScript program

< html >

< body >

< script >

var k,t; // variable declaration

for (k = 1; i < 6; k++) // iterating the loop

{

t=k*k*k;// find the cube of number

document.write(k); // display the cube root

document.write(" < / br > " ); // moves to the next line

}

< / script >

< / body >

< / html >

Output:

1

8

27

64

125

Step-by-step explanation:

  • We used the script tag for creating the JavaScript program.
  • Declared the variable "k" in the script tag.
  • Iterating the for loop .In the for loop the k variable is initialized by the 1 This loop is executed less then 6 .
  • In each iteration we find the cube of number in the "t" variable and display that number by using document .write ().

User Orlandster
by
8.7k points

No related questions found