Addition program in c

In this example, we take two integer input from user and print addition of them using User Define Function.

C Program to Add Two Integer Value With Function :

We are going to use scanf() function to taking user input and printf() function to print. In Below code we have created sum() function which take two argument and return answer.

What is User Define Function(UDF)?

A user-defined function (UDF) is a common fixture in programming languages, and the main tool of programmers for creating applications with reusable code.

Example :

#include <stdio.h>
int sum(int a, int b){
    return a+b;
int main()
    int num1, num2, num3;
    printf("Enter first number: ");
    scanf("%d", &num1);
    printf("Enter second number: ");
    scanf("%d", &num2);

    //Calling the function
    num3 = sum(num1, num2);
    printf("Sum of the two numbers: %d", num3);
    return 0;

Output :

        Enter first number: 10
		Enter second number: 20
		Sum of the two numbers: 30

Share your thoughts

Ask anything about this examples