1
1.Write a c program to find out the sum of series
1^3 + 2^3 + …. + n^3
Mathematical Formula:
Sum of the series 13
+ 23
+ 33
+ … + n3
= (n (n+1)/2)2
#include<stdio.h>
#include<math.h>
int main(){
int n,i;
int sum=0;
printf("Enter the n i.e. max values of series: ");
scanf("%d",&n);
sum = pow(((n * (n + 1) ) / 2),2);
printf("Sum of the series : ");
for(i =1;i<=n;i++){
if (i != n)
printf("%d^3 + ",i);
else
printf("%d^3 = %d ",i,sum);
}
return 0;
}
Sample output:
Enter the n i.e. max values of series: 3
Sum of the series: 1^3 + 2^3 + 3^3 = 36
OR
#include "math.h"
int main(){
2
int sum=0,i=0,n;
scanf("%d",&n);
for(i=1;i<=n;i++){
sum = sum + pow(i,i+1);
}
printf("Sum of series: %d" sum);
}
2.Write a c program to find out the sum of series 1
+ 2 + …. + n.
#include<stdio.h>
int main(){
int n,i;
int sum=0;
printf("Enter the n i.e. max values of series: ");
scanf("%d",&n);
sum = (n * (n + 1)) / 2;
printf("Sum of the series: ");
for(i =1;i <= n;i++){
if (i!=n)
printf("%d + ",i);
else
printf("%d = %d ",i,sum);
}
return 0;
}
Sample output:
Enter the n i.e. max values of series: 5
Sum of the series: 1 + 2 + 3 + 4 + 5 = 15
Mathematical Formula:
3
Sum of the series 1 + 2 + 3 + … + n = n (n+1)/2
3.Write a c program to find out the sum of series
1^2 + 2^2 + …. + n^2.
#include<stdio.h>
int main(){
int n,i;
int sum=0;
printf("Enter the n i.e. max values of series:
");
scanf("%d",&n);
sum = (n * (n + 1) * (2 * n + 1 )) / 6;
printf("Sum of the series : ");
for(i =1;i<=n;i++){
if (i != n)
printf("%d^2 + ",i);
else
printf("%d^2 = %d ",i,sum);
}
return 0;
}
Sample output:
Enter the n i.e. max values of series: 5
Sum of the series: 1^2 + 2^2 + 3^2 + 4^2 + 5^2 = 55
Mathematical Formula:
Sum of the series 12
+ 22
+ 32
+ … + n2
=
n (n+1) (2n+1)/6

Progr2

  • 1.
    1 1.Write a cprogram to find out the sum of series 1^3 + 2^3 + …. + n^3 Mathematical Formula: Sum of the series 13 + 23 + 33 + … + n3 = (n (n+1)/2)2 #include<stdio.h> #include<math.h> int main(){ int n,i; int sum=0; printf("Enter the n i.e. max values of series: "); scanf("%d",&n); sum = pow(((n * (n + 1) ) / 2),2); printf("Sum of the series : "); for(i =1;i<=n;i++){ if (i != n) printf("%d^3 + ",i); else printf("%d^3 = %d ",i,sum); } return 0; } Sample output: Enter the n i.e. max values of series: 3 Sum of the series: 1^3 + 2^3 + 3^3 = 36 OR #include "math.h" int main(){
  • 2.
    2 int sum=0,i=0,n; scanf("%d",&n); for(i=1;i<=n;i++){ sum =sum + pow(i,i+1); } printf("Sum of series: %d" sum); } 2.Write a c program to find out the sum of series 1 + 2 + …. + n. #include<stdio.h> int main(){ int n,i; int sum=0; printf("Enter the n i.e. max values of series: "); scanf("%d",&n); sum = (n * (n + 1)) / 2; printf("Sum of the series: "); for(i =1;i <= n;i++){ if (i!=n) printf("%d + ",i); else printf("%d = %d ",i,sum); } return 0; } Sample output: Enter the n i.e. max values of series: 5 Sum of the series: 1 + 2 + 3 + 4 + 5 = 15 Mathematical Formula:
  • 3.
    3 Sum of theseries 1 + 2 + 3 + … + n = n (n+1)/2 3.Write a c program to find out the sum of series 1^2 + 2^2 + …. + n^2. #include<stdio.h> int main(){ int n,i; int sum=0; printf("Enter the n i.e. max values of series: "); scanf("%d",&n); sum = (n * (n + 1) * (2 * n + 1 )) / 6; printf("Sum of the series : "); for(i =1;i<=n;i++){ if (i != n) printf("%d^2 + ",i); else printf("%d^2 = %d ",i,sum); } return 0; } Sample output: Enter the n i.e. max values of series: 5 Sum of the series: 1^2 + 2^2 + 3^2 + 4^2 + 5^2 = 55 Mathematical Formula: Sum of the series 12 + 22 + 32 + … + n2 = n (n+1) (2n+1)/6