Program to Find the sum of series 3+7+13+21.....+N

 Problem statement:- Program to Find the sum of series 3+7+13+21+31.....+N.


 Data requirement:-

   Input Data:- n

  Output Data:-Sum

  Additional Data:- i

Program in C
  
Here is the source code of the C Program to Find the sum of series 3+7+13+21+31.....+N.

Code:

#include<stdio.h>
int main()
{
    int n;
    int sum=0,i;
    printf("Enter the range of number:");
    scanf("%d",&n);
    for(i=2;i<=n+1;i++)
    {

            sum+=1+(i*(i-1));
    }
    printf("The sum of the series = %d",sum);
}

Input/Output:
Enter the range of number:5
The sum of the series = 75

Program in C++

Here is the source code of the C++ Program to Find the sum of series 3+7+13+21+31.....+N.

Code:

#include<iostream>
using namespace std;
int main()
{
    int n;
    int sum=0,i;
    cout<<"Enter the range of number:";
    cin>>n;
    for(i=2;i<=n+1;i++)
    {

            sum+=1+(i*(i-1));
    }
   cout<<"The sum of the series = "<<sum;
}

Input/Output:
Enter the range of number:4
The sum of the series = 44

Program in Java

Here is the source code of the Java Program to Find the sum of series 3+7+13+21+31.....+N.

Code:

import java.util.Scanner;
public class Sum_Of_Series9 {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int n;
int sum=0,i;
     System.out.println("Enter the range of number:");
     n=cs.nextInt();
     for(i=2;i<=n+1;i++)
     {

             sum+=1+(i*(i-1));
     }
     System.out.println("The sum of the series = "+sum);
     cs.close();
}
}

Input/Output:
Enter the range of number:
8
The sum of the series = 248

Program in Python

Here is the source code of the Python Program to Find the sum of series 3+7+13+21+31.....+N.

Code:

n=int(input("Enter the range of number:"))
sum=0
for i in range(2,n+2):
    sum+=1+(i*(i-1))
print("The sum of the series = ",sum)

Input/Output:
Enter the range of number:3
The sum of the series =  23


Post a Comment

0 Comments