Write a program in C++ to calculate the sum 1+x+x+ x2 +....n terms.
Answers
Answered by
3
Explanation:
#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;
}
Similar questions
Math,
1 month ago
Social Sciences,
1 month ago
Math,
2 months ago
Biology,
2 months ago
English,
10 months ago
Social Sciences,
10 months ago
Biology,
10 months ago