+ 1

If i have done some mistake so please explain.

Sum of series 1+2+4+7+11....+n terms https://code.sololearn.com/cKq3NG8yYF8A/?ref=app

12th Dec 2018, 9:19 AM
Lata Mishra
Lata Mishra - avatar
8 Antworten
+ 18
#include <stdio.h> int main() { int i,N,term=1,sum=0; //● term for current term //● variable sum for summing up terms //clrsr() printf("enter the value of N:\n"); scanf("%d",&N); for(i=1;i<=N;i++) { sum=sum+term; //● for adding terms to sum variable term=term+i; //● for getting to next term } printf("sum of series:%d",sum); //● printing sum here , not N return 0; }
12th Dec 2018, 9:45 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 13
Lata Mishra ● in your code, U have used sum variable [it was not calculating sum of N terms, but it was calculating (N+1)th term of series] //see comments I made in above answer for better understanding 👍
12th Dec 2018, 9:53 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 4
line no. 12 printf("sum of series :%d", sum); you are supposed to print the sum not the input
12th Dec 2018, 9:49 AM
‎ ‏‏‎Anonymous Guy
+ 4
which term?
12th Dec 2018, 9:52 AM
‎ ‏‏‎Anonymous Guy
+ 4
term is the difference between two consecutive numbers that are to be added term for 1 and 2 is 1 term for 2 and 4 is 2 term for 4 and 7 is 3 and so on...
12th Dec 2018, 9:57 AM
‎ ‏‏‎Anonymous Guy
+ 2
Still confused why i need to use "term"
12th Dec 2018, 9:51 AM
Lata Mishra
Lata Mishra - avatar
+ 2
Used by Gaurav agrawal
12th Dec 2018, 9:53 AM
Lata Mishra
Lata Mishra - avatar
+ 2
Ok but you should first explain mistakes and talk respectfully
12th Dec 2018, 10:32 AM
Lata Mishra
Lata Mishra - avatar