Computer Science, asked by mashu01durrani, 3 months ago

Write different programs to print the given series:
1000 81 512 49 216 25 64 9 8 1​

Answers

Answered by allysia
2

Using JAVA:

Program:

public class oh {

public static void main(String[] args) {

 /*

  * 1000 81 512 49 216 25 64 9 8 1​

  */

 int a = 10;

 int j = 9;

 for (int i = 1; i < 6; i++) {

  System.out.print(Math.round(Math.pow(a, 3)) + " ");

  System.out.print(Math.round(Math.pow(j, 2)) + " ");

  a = a - 2;

  j = j - 2;

 }

}

}

Using Python:

Program:

a=10

b=9

for i in range (1,6):

   print(a**3, b**2, end=" ")

   a-=2

   b-=2

Explanation:

In JAVA I used .round method to convert decimal to int.

Attachments:
Answered by anindyaadhikari13
3

Required Answer:-

Question:

  • Write a program to print the series:- 1000 81 512 49 216 25 64 9 8 1

Solution:

This is written in Java.

  1. public class JavaBrainly {
  2. public static void main(String[] args) {
  3. int a=3, b=2;
  4. for(int i=10;i>=1;i--)
  5. {
  6. System.out.print((int)Math.pow(i,a)+" ");
  7. int c=a;
  8. a=b;
  9. b=c;
  10. }
  11. }
  12. }

This is written in Python.

  1. a,b=3,2
  2. for i in range(10,0,-1):
  3. print(i**a,end=" ")
  4. a,b=b,a

Explanation:

Logic is as follows,

1000 = 10³

81 = 9²

512 = 8³ and so on.

So, it's like n³, n²

After each iteration, variable 'i' is raised to the power a where a = 3 and b = 2. At the same time, the values of a and b are swapped. So, variable 'i' is raised to the power 3 and then to the power 2, then again 3,2 and so on.

Output is attached for verification.

Attachments:
Similar questions