Q:

I am trying to write a function in C to sum two numbers, but I am not getting the expected answer

I've been trying to do a program which sums two numbers; I want to use a function to do that.  The function is called "sum".  With the code shown below I get "the sum is 0".  What am I doing wrong? 
#include <stdio.h>

int sum()

{
    int a, b;
    int answer;
    answer = a+b;
    return 0;
}

int main()
     {
        int var_a,  var_b;
        int result;

        printf (" first number \n");
        scanf ("%i",&var_a);
        printf ("second number \n");
        scanf ("%i",&var_b);
            result = sum(var_a,var_b);

        printf(" The sum is %i", result);

        return 0;       
     }

A:

There are two problems with your function sum
First, the return value should be answer, not 0, otherwise no matter how you call this function, it always gives you 0.  So change return 0; to return answer;. 
Second, you are clearly aware that function sum takes arguments from outside when you do: result = sum(var_a,var_b); in your main.  So you should define your function sum accordingly like:
int sum(int a, int b)

{
    int answer;
    answer = a+b;
    return answer;
 }

