C PROGRAM TO ADD TWO NUMBERS USING FUNCTION
C PROGRAM TO ADD TWO NUMBERS / INTEGERS USING FUNCTION
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#include<stdio.h> #include<conio.h> int sum(int,int); /*declaring prototype of function*/ void main() { int a,b,c; printf("n Enter the two numbers : "); scanf("%d %d",&a,&b); /* taking two numbers as input*/ c = sum(a,b); /* calling function, *the value returned by the function is stored in c */ printf("n The sum of two numbers is : %d ",c); getch(); } int sum ( int num1,int num2) { int result; /* defining variable, its scope lies within function */ result = num1 + num2 ; /*adding two numbers*/ return (result) ; /* returning result */ } |
Sample Output :
