Computer Science, asked by JoyeetaDas, 7 months ago

write a program to find the series 2 12 30 56...n in java​

Answers

Answered by k047
1

❤ⒽⒺⓁⓁⓄ❤

Input: N = 2

Output: 8

2 + 6

= 8

Input: N = 4

Output: 40

2 + 6+ 12 + 20

= 40C++ program to find sum of first n terms

#include <bits/stdc++.h>

using namespace std;

// Function to calculate the sum

int calculateSum(int n)

{

return n * (n + 1) / 2 + n *

(n + 1) * (2 * n + 1) / 6;

}

// Driver code

int main()

{

// number of terms to be

// included in the sum

int n = 3;

// find the Sn

cout << "Sum = " << calculateSum(n);

return 0;

hope it help you

꧁CHɑUHɑN SɑɑB ꧂

βyё♥βyё

Answered by Akshithayadav
1

Answer:

import java.util.Scanner;

class test{

public static void main(String[] ards){

int a = 1;

int b = 1;

Scanner sc = new Scanner(System.in);

System.out.println("Enter the limit of the sequence:");

int n = sc.nextInt();

int c=1;

for(int i = 0; i < n; i++){

if(i < 2)

System.out.println(a);

else

{

c = a +b;

if((i+1)%4 == 0)

c *= 4;

System.out.println(c);

a = b;

b = c;

}

}

}

}

Explanation:

hope it helps you

please mark me as brainliest please

Similar questions