Write a program to print following series:
0 3 8 . . . n term
PLEASE , WRITE INPUT ,OUTPUT AND VARIABLE DESCRIPTION TABLE ALSO
Answers
Answer:
How the series works-
1*1-1 = 0
2*2-1 = 3
3*3-1 = 8
upto n
program-
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("How many elements are there in the series:");
int n = sc.nextInt();
for(int i = 1; i <= n; i++){
int d = (i*i)-1;
System.out.print(d + " ");
}
}
}
Explanation:
Hope it helps ^_^
This program is in Java
import java.util.Scanner;
public class Serial_Printer{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("This program prints the series 0, 3, 8, ... n terms");
System.out.println("How this series work: ");
System.out.println("(1×1)-1 = 0");
System.out.println("(2×2)-1 = 3");
System.out.println("(3×3)-1 = 8");
System.out.println("upto n");
System.out.print("Enter the number upto which the series is to be printed:");
int n = sc.nextInt();
for(int i = 1; i <= n; i++){
int j = (i * i)-1;
System.out.print(j + " ");
}
}
}
The underlined value is the user-input
Output:
This program prints the series 0, 3, 8, ... n terms
How this series work:
(1×1)-1 = 0
(2×2)-1 = 3
(3×3)-1 = 8
upto n
Enter the number up to which the series is to be printed:5
0 3 8 15 24