Menu Close

C Program to Add Two Numbers Using Functions

In this article we will learn about C Program to Add Two Numbers Using Functions. We will define here a custom function which returns the sum of two numbers. Then we call the custom function in the main function and print the result. Please read my all articles of C-Programming here.

Check the YouTube shorts below,

C Program to Add Two Numbers Using Functions

#include<stdio.h>

//define the user defined function of Add()

int sum_digit(int x, int y){
    return x+y;
}

int main(){
    int a , b ,sum;

    //addin inputs
    printf("Enter First Number: ");
    scanf("%d", &a);
    printf("Enter the second Number: ");
    scanf("%d", &b);

    // calling the out function
sum= sum_digit(a,b);

// dispaly the output

printf("sum of two numbers is: %d", sum );

return 0;

}

To run the application you can see the output like below,

C Programming with adding numbers

Code Explanation

  • We have defined a custom function named sum_digit which returns the sum of two numbers.
int sum_digit(int x, int y){
    return x+y;
}

  • We have defined a custom function named sum_digit which returns the sum of two numbers.
  • Then, we call the custom function in the main function. This gives us the sum of two numbers. This gets stored in the sum named variable.
// calling the out function
sum= sum_digit(a,b);

// dispaly the output

printf("sum of two numbers is: %d", sum );

Conclusion

We discussed here how to add two numbers using functions in C Programming language.

Leave behind your valuable queries and suggestions in the comment section below. Also, if you think this article helps you, do not forget to share this with your developer community. Happy Coding 🙂

Related Articles

Jayant Tripathy
Coder, Blogger, YouTuber

A passionate developer keep focus on learning and working on new technology.

Leave a Reply

Your email address will not be published. Required fields are marked *