- On
- By
- 2 Comments
- Categories: addition, Calculations
C program to add two numbers using function
C program to add two numbers using the function
In this tutorial, we will learn C program to add two numbers using the function
In this topic, we will learn a simple concept of how to add two number using the function in C programming language
already we know the same concept using the operator in a simple way.
if you knew click here C program to the sum of two numbers
This program has following procedures to completion
- Function declaration or prototype
- Ask input from the user for values
- Define the function
- Call the function
- Display result on the screen
Program 1
#include <stdio.h> #include <stdlib.h> int sum(int , int);//function declaration or prototype int main() { int num1,num2,total;//variable declaration printf("Enter the two number "); scanf("%d %d",&num1,&num2);//getting two number as input from user total=sum(num1,num2);//calling the function //The total value (returned by the function) is stored in total variable. printf("The sum of these numbers :%d",total); //display the total value getch(); return 0; } int sum(int a, int b)//defining function based in declaration { int result=a+b;//find sum of two numbers //and result of sum stored in result variable return result;//returning result }
When the above code is compiled and executed, it produces the following results
Enter the two numbers 45 75 The sum of these numbers :120
Suggested for you
2 Comments
Anish Chaakraborty April 20, 2020 at 6:11 am
Why there result variable is not declared?
Karmehavannan April 21, 2020 at 4:59 am
The result variable was declared in the line number 18
NARESH KUMAR SHARMA October 30, 2021 at 9:26 am
As I write a program in c language as per prescribed I got errors like syntax ,prototype,statement is missing, unterminated string or character constant . I am a fresher you are requested to send me a fully solved program like sum of two integers. on my e mail. [email protected]. NARESH KUMAR SHARMA