I’m trying to make code of 1+3+5+7+…99 in C program without using loop means using formula -
n/2(2*a + (n - 1)*d
a = First term
d= Common difference
n=Value of number
Summation of n?
BUT, It shows an ERROR!
error: called object is not a function or function pointer
Here is my Code—
#include <stdio.h>
int main()
{
int sum_of_n,value_of_n,value_of_a,value_of_d;
printf("Please enter the value of n: ");
scanf("%d", &value_of_n);
printf("Please enter the value of a: ");
scanf("%d", &value_of_a);
printf("Please enter the value of d: ");
scanf("%d", &value_of_d);
sum_of_n = value_of_n/2(2*value_of_a+(value_of_n-1)*value_of_d);
printf("Summation of this series is: %d", &sum_of_n);
return 0;
}
Please try to help me,I will grateful to you
Thank you~
Oh I see you are trying to translate the formula from paper.
value_of_n/2 is halve the number of terms you are adding.
n-1 is one less than the total number of terms.
d is the difference between two consecutive terms.
Hang on a minute, let me get some pen and paper to work it out on paper.
What’s wrong here ?
I’m trying to make 1+3+…+9 this series
here n = 5 (Cus There is 5 even and 5 odd number,we just count odd)
and a(first term) = 1
and d(common difference)=2
if we sum this series by hand then 1+3+5+7+9=25 .
Answer should be 25 .But my answer is 6356732