In this tutorial you will learn about the C Program to Find Sum of series 1²+2²+3²+….+n² and its application with practical example.
C Program to Find Sum of series 1²+2²+3²+….+n²
In this tutorial, we will learn to create a C program that will Find the Sum of series 1²+2²+3²+….+n² using C programming.
Prerequisites
Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- Mathematical Functions in C Programming.
What is a Series?
The series is a number pattern from a starting point to a specific point, with a special difference between its two terms. The series can be of difference between the terms, the ratio between the term, or a specific logic between the two terms.
Programs to Find Sum of Series:-
In this tutorial, we will learn to create a program that will find the sum of the given series using a mathematical expression and the pre-defined functions. First, we will take the input from the user in the form of an integer value. Then we will calculate the sum of squares of the series using the predefined mathematical function and arithmetic expressions. At last, we will print the sum of the series.
Program Code:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
/* C program to find the Sum of square of n Natural numbers */ #include <stdio.h> #include <math.h> int main()//Body of the main function. { //Declaring the required variables for the program. int no, Sum = 0; //no = it will hold the integer value for the input number. //Sum = it will hold the sum of the cube of integer //Taking the number from the user printf("\n Please Enter any positive integer \n"); scanf(" %d",&no); //Calculating the sum. Sum = (no * (no + 1) * (2 * no + 1 )) / 6; //Printing the output um of series. printf("\n The Sum of Series for %d = %d ",no, Sum); } |
Output:-
In the above program, we have first initialized the required variable
- no = it will hold the integer value.
- sum = it will hold the integer value.
Taking the number of terms from the user.
Finding the sum of the square of the series.
Program Code for Printing the sum of squares of series.