Add two numbers using the function in C
Here we will learn how to add two numbers by creating function in C. Let’s learn this with help of example.
Code: -
#include <stdio.h>
int add_two_no(int a, int b);
int main(){
int first_num, second_num, sum;
printf("Enter the first number: ");
scanf("%d”, &first_num);
printf("Enter the second number: ");
scanf("%d”, &second_num);
sum = add_two_no(first_num, second_num);
printf ( "Sum of the entered number: %d”, sum);
return 0;
}
int add_two_no(int a, int b){
return (a + b);
}
Output: -

Explanation:-
In the above code, three integer variables are named first_num,second_num, and sum.
After that, the user is asked to enter inputs, and it is stored in variables first_num and second_num.
After that user-defined function is created named add_two_no for calculating the addition of two numbers and is called for the same purpose.
The user-defined function named add_two_no passes two numbers as an argument/parameter and returns the sum of the two numbers.
And in the last is displayed using printf statement.