➤ If-else Statement in C
➤ Programs on if-else
➤ Switch Case in C
➤ Switch case Programs
➤ Conditional Operator
➤ While loop in C
➤ Do-while loop in C
➤ While vs do-while
➤ For loop in C
➤ Break keyword in C
➤ Continue keyword in C
➤ Break vs Exit in C
➤ Goto keyword in C
☕️ Flow Control Programs
➤ Largest in 3 Numbers
➤ Find Grade of student
➤ Find the absolute value
➤ Vowel or Consonant
➤ Leap Year Program
➤ Simple calculator in C
➤ Check Odd or Even
➤ Roots of Quadratic Equation
➤ Find Reverse of Number
➤ Factors of a number in C
➤ Generate Multiplication table
➤ Find Power of a Number
➤ Find GCD and LCM
➤ Find factorial of Number
➤ Count Number of Digits
➤ Sum of digits in Number
➤ Sum of N Natural Numbers
➤ Sum of Squares of Natural No.
➤ Find Sum of Odd Numbers
➤ Find the Sum of Series
➤ Find Fibonacci series in C
➤ Sum of the Fibonacci series
➤ Sum until enters +ve numbers
➤ Sum of max 10 no. & Skip -ve
☕️ C Conversion Programs
➤ Celsius to Fahrenheit
➤ Fahrenheit to Celsius
➤ Decimal ↔ Binary
➤ Decimal ↔ Octal
➤ Octal ↔ Binary in C
☕️ Number Programs in C
➤ Prime Number in C
➤ Strong Number in C
➤ Krishnamurthy Number
➤ Neon Number in C
➤ Palindrome number
➤ Perfect Number in C
➤ Armstrong Number
☕️ Pattern Programs in C
➤ Pattern programs in C
➤ Printing pattern using loops
➤ Floyd’s triangle Program
➤ Pascal Triangle Program
➤ Pyramid Star Pattern in C
➤ Diamond Pattern Programs
➤ Half Diamond pattern in C
➤ Print Diamond Pattern
➤ Hollow Diamond Pattern
➤ Diamond Pattern of Numbers
In this tutorial we will write sum of series program in C language. Some series as 1+2+3+4+5+…+n, 1 + 1/2 + 1/3 + 1/4 + 1/5 + 1/6 +……+ 1/n and 1 + 1/(2*2) + 1/(3*3) + 1/(4*4) + ….. + 1/(n*n)
Sum of series in C 1+2+3+4+5+..+N
Program Description:- Display sum of series 1+2+3+4+5+..+n = ?
Sample Input Output-1:-
Enter n value: 5
1+2+3+4+5=15
Sample Input Output-2:-
Enter n value: 15
1+2+3+4+5+6+7+8+9+10+11+12+13+14+15=120
#include<stdio.h>
int main()
{
int n, sum=0;
printf("Enter n value: ");
scanf("%d",&n);
for(int i=1; i<=n; i++)
{
printf("%d+",i);
sum += i; //sum = sum + i;
}
printf("\b=%d",sum);
return 0;
}
In this program ‘\b’ character used to remove last ‘+’ character. If we don’t use ‘\b’ then for n=5 we will get below output,
Enter n value: 5
1+2+3+4+5+=15
Enter n value: 10
1+2+3+4+5+6+7+8+9+10=55
Sum of series in C language 1² + 2² + 3² + 4² + 5² +….+ n²
Program description:- Find sum of series 1² + 2² + 3² + 4² + 5² +….+ n² = ?
Sample Input Output 1
Enter n value: 5
Sum = 55
Sample Input Output 2
Enter n value: 12
Sum=650
#include<stdio.h>
int main()
{
int n, sum=0;
printf("Enter n value: ");
scanf("%d",&n);
for(int i=1; i<=n; i++)
{
sum += i*i; //sum = sum + (i*i);
}
printf("Sum=%d",sum);
return 0;
}
Enter n value: 7
Sum = 140
Sum of series 1 + 1/2 + 1/3 + 1/4 + 1/5 + 1/6 +……+ 1/n
Using For Loop
#include<stdio.h>
int main()
{
int n,i;
float sum=0.0;
printf("Enter the limit (n Value): ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
sum+=(1.0/i); //sum = sum + 1.0/i
}
printf("Sum = %f\n", sum);
return 0;
}
1 + 1/2 + 1/3 + 1/4 + 1/5 + 1/6 +……+ 1/n using While Loop
#include<stdio.h>
int main()
{
int n, i=1;
float sum=0.0;
printf("Enter the limit (n Value): ");
scanf("%d",&n);
while(i<=n)
{
sum+=(1.0/i); //sum = sum + 1.0/i
i++;
}
printf("Sum = %f\n", sum);
return 0;
}
Output:-
Enter the limit (n Value): 50
Sum = 4.499206
1 + 1/(2*2) + 1/(3*3) + 1/(4*4) + ….. + 1/(n*n)
Using For Loop
#include<stdio.h>
int main()
{
int n,i;
float sum=0.0;
printf("Enter the limit (n Value): ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
sum+=(1.0/(i*i)); // sum = sum + (1.0 / (i*i) )
}
printf("Sum = %f", sum);
return 0;
}
1 + 1/(2*2) + 1/(3*3) + 1/(4*4) + ….. + 1/(n*n) using While Loop
#include<stdio.h>
int main()
{
int n, i=1;
float sum=0.0;
printf("Enter the limit (n Value): ");
scanf("%d",&n);
while(i<=n)
{
sum+=(1.0/(i*i)); // sum = sum + (1.0 / (i*i) )
i++;
}
printf("Sum = %f\n", sum);
return 0;
}
Sum of series in C language 1 + 1/(2*2) + 1/(3*3) + 1/(4*4) + ….. + 1/(n*n) using pow() Function
Using pow() function, we can use either while loop or for
#include<stdio.h>
#include<math.h>
int main()
{
int n, i=1;
float sum=0.0;
printf("Enter the limit (n Value): ");
scanf("%d",&n);
while(i<=n)
{
sum+=(1.0/pow(i,2)); //sum = sum + 1.0/ pow(i,2)
i++;
}
printf("Sum = %f", sum);
return 0;
}
Output:-
Enter the limit (n Value): 50
Sum = 1.625133
In this sum of series in C language program, If you are using Linux/Unix OS and getting an error then read it “undefined reference to sqrt (or other mathematical functions)” even include math.h header
If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!