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,
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
- Create a RESTful CRUD API With NodeJS, ExpressJS And MongoDB – Complete Guide
- How to run a React Native app on Windows: Setup React Native Environment
- Create a responsive sidebar with Angular Material- Angular 18 Example Series
- How to Deploy Angular 17/18 App in GitHub Pages
- .NET 8 Authentication with Identity in a Web API using Bearer Tokens and Cookies
Jayant Tripathy
Coder, Blogger, YouTuberA passionate developer keep focus on learning and working on new technology.