C programming, error: called object is not a function or function pointer

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 :heart:
Thank you~

What does this do?
value_of_n/2 ( 2*value_of_a+(value_of_n-1)*value_of_d);

This is probably telling the compiler to treat it as a function call and not a multiplication.

1 Like

What should i do ? :frowning:

Just add a multiplication sign.

sum_of_n = value_of_n/2(2*value_of_a+(value_of_n-1)*value_of_d);

should be

sum_of_n = value_of_n/2*(2*value_of_a+value_of_n-1*value_of_d);

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.

1 Like

Thank you sir :heart::heart::heart:

What’s wrong here ? :frowning:
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 :roll_eyes:

Ok, did some quick math on paper.

1+3+5+7+9+11+13+15+…+99 =
sum(j=1…50, 2j-1) = sum(j=1…50,2j)-sum(j=1…50,1) =
2*sum(j=1…50,j)-50, the first term is a regular arithmetic sum.

You could also solve it as

Sum(j=1…50,2*j-1) in that case
value_of_n = 50
value_of_a = 1
and value_of_d = 2

1 Like


Why answer is still 6356732 ? :roll_eyes:

printf("%d", &sum_of_n) 

prints the memory adress of the variable sum_of_n

printf("%d", sum_of_n);

notice, no & prints the value of the variable sum_of_n.

1 Like


Oh,Thank you soo much :heart::heart::heart::heart::heart::heart::heart:
Now i found myself as a dumb :see_no_evil: