C Program to Find Sum of series 1²+2²+3²+…+n²


0

Program to find the sum of series 1²+2²+3²+.+n² in C; Through this tutorial, we will learn how to find the sum of series 1²+2²+3²+….+n² using for loop in C Programming Language.

C Program to Find Sum of series 1²+2²+3²+…+n²

Finding the sum of a series of numbers is a common task in mathematics. In this blog post, we will discuss how to calculate the sum of the series 1²+2²+3²+…+n² using the C programming language.

The first step is to define the series. In this case, the series is 1²+2²+3²+…+n². This means that we are adding the squares of the numbers from 1 to n.

Next, we need to create a program to calculate the sum of the series. We can do this by using a for loop. The for loop will iterate from 1 to n and add the square of each number to a running total. Once the loop is complete, the total will be the sum of the series.

Programs to Find Sum of series 1²+2²+3²+….+n² in C

C Program to Find Sum of series 1²+2²+3²+….+n² using For Loop

Here is the code for the program:

#include<stdio.h>
int main()
{
   int n, sum=0;

   printf("Enter The value Of N: ");
   scanf("%d",&n);

   for(int i=1; i<=n; i++)
   {
     //sum = sum + (i*i);
     sum += i*i; 
   }

   printf("The sum of the series 1²+2²+3²+…+n² is %d", sum);

   return 0;
}

This program will take input from the user (n) and then calculate the sum of the series 1²+2²+3²+…+n².

Finally, we can test the program by running it with different values of n. For example, if we enter 5 as the value of n, the program will output the sum of the series 1²+2²+3²+4²+5², which is 55.

We have now successfully written a program to calculate the sum of the series 1²+2²+3²+…+n² using the C programming language.


Like it? Share with your friends!

0
mrwixxsid

0 Comments

Choose A Format
Personality quiz
Series of questions that intends to reveal something about the personality
Trivia quiz
Series of questions with right and wrong answers that intends to check knowledge
Poll
Voting to make decisions or determine opinions
Story
Formatted Text with Embeds and Visuals
List
The Classic Internet Listicles
Countdown
The Classic Internet Countdowns
Open List
Submit your own item and vote up for the best submission
Ranked List
Upvote or downvote to decide the best list item
Meme
Upload your own images to make custom memes
Video
Youtube and Vimeo Embeds
Audio
Soundcloud or Mixcloud Embeds
Image
Photo or GIF
Gif
GIF format