How to use find the sum of two numbers in C Language

Sum Two Numbers

On this page

Sum Two Numbers

Program to use Find the Sum of Two Numbers in C Language

#include <stdio.h>
int sum(int x, int y); /*Function declaration*/
int main()
{
    int a, b, s;
    printf("Enter values for a and b :");
    scanf("%d %d", &a, &b);
    s = sum(a, b); /*Function call*/
    printf("Sum of %d and %d is %d\n", a, b, s);
    return 0;
}
int sum(int x, int y) /*Function definition*/
{
    int s;
    s = x + y;
    return s;
}

Output

Enter values for a and b :5
4
Sum of 5 and 4 is 9