Skip to main content

C Program to find the sum of the series 1^2+2^2+3^2+…..+n^2

C Program to find the sum of the series 12+22+32+…..+n2
Enter the end limit at the runtime.
 

    In this example, we calculate the sum of the above mentioned series till the end-limit entered by the user. We have used built-in function pow(x,y) to find the power of the given number.

    Here in the output we have entered the value of end-limit as number 7 which gives a sum of 140.  

PROGRAM

#include<stdio.h>
#include<math.h>
#include<conio.h>
void main()
{
    int n,sum=0,i;
    printf("Enter the end limit :");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        sum=sum+pow(i,2);
    }
    printf("Sum of the series is : %d",sum);
    getch();
}


OUTPUT

 Enter the end limit :7

 Sum of the series is : 140



NOTE: You Can Comment Your Code if you have solved differently and we will pin it in the comment section.  Let's Learn together. 


MOTTO: 

You Learn, I Learn together We Learn.

Comments

Popular posts from this blog

C Program to input and display details of students using structure

 C Program to input and display details of students using structure.       In this example, we will enter the details of students like roll number, name and total marks using structure and will be displayed. The total number of student should be entered according to the requirements of the user(maximum value is 50). We can increase the maximum number by changing the statement struct student[50];  to struct student[100];     Here in the output we have entered details of four student and displayed them accordingly. PROGRAM #include <stdio.h> #include <conio.h> struct   student {      int   roll ;      char   name [ 20 ];      int   total ; }; void   main () {      int   i , n ;      struct   student   std [ 50 ];      printf ( "Enter the number of students ...

C Program to Check a Whether a Number is Divisible by 5 or Not

 C Program to Check a Whether a Number is Divisible by 5 or Not            In this program we will check a number entered by the user will be divisible by 5 or Not. We have solved this problem using if-else statement. Program: #include <stdio.h> #include <conio.h> int  main() {      int  x;     printf( "Enter a number" );     scanf( "%d" ,&x);      if (x% 5 == 0 )         printf( "The number %d is divisible by 5" ,x);      else         printf( "The number %d is not divisible by 5" ,x);      return   0 ; } Output: NOTE:   You Can Comment Your Code if you have solved differently and we will pin it in the comment section.  Let's Learn toget...

C program to calculate area of a circle using function.

C program to calculate area of a circle. In this example we will learn to calculate the area of a circle. Here in this program we will use 3.14 as the value of pi.  The formula to calculate the area of a circle is:                                                         area=   π  r² Flowchart To Calculate the Area of a Circle: PROGRAM: #include <conio.h> #include <stdio.h> int   main () {      float   radius , area ;      printf ( "Enter the radius of the circle : " );      scanf ( "%f" ,& radius );      area = 3.14 * radius * radius ;          printf ( "Area of the circle is : %.2f" , area );  ...

C Program to print the values of the diagonal elements of a square matrix and also find the sum of the values of the diagonal elements

C Program to print the values of the diagonal elements of a square matrix and also find the sum of the values of the diagonal elements.     In this example, we will accept the values of a square matrix and will print the diagonal elements of the of the square matrix, also the sum of the values of the diagonal elements will be printed.     Here, in the output we have taken a 3x3 square matrix.     PROGRAM #include <stdio.h> #include <conio.h> void   main () {      int   a [ 50 ][ 50 ], row , column , i , j , sum = 0 ;      printf ( "Enter the row size of the square matrix : " );      scanf ( " %d " ,& row );      column = row ;      printf ( "As this is a square matrix the row size and column size are equal." );  ...