+ 1
#include <stdio.h> int main() { int k,sum ; printf("number of terms in series = %d", k); scanf("%d",&k); sum = k*(k-1)/2; print
Whenever i am run it & enters any value of k. It only show no. Of terms =8
2 odpowiedzi
+ 2
Since you didn't initialize variable <k>, its value is unpredictable, also, you are printing the value of <k> before you read the input for it. Try to swap the line `printf("number of terms ...` with the `scanf("%d", &k);` line, then see if it helps.
P.S. Your last line says `print` only, either the code is truncated or what I'm not sure. For future reference, put code in Description section (if it is small <= 10 lines). Or save the code in your profile and share the code link instead, if it's big (>= 10 lines, again in Description section).
+ 2
If this is an arithmetic series, shouldn't the sum be k*(k+1)/2 ?