Computer Programming C Laboratory: Functions C Programs

C Program for addition of two numbers (Function with arguments and with return value)

Function with arguments and with return value - C Programming

Addition of two numbers.

* C Program for addition of two numbers */

#include <stdio.h>

main()

{

int add(int, int); /* Local definition */

int a,b,c;

/* Statements */

printf("Enter two numbers :");

scanf("%d %d", &a, &b);

c=add(a,b); /* add is a function with arguments */

printf("Result is ...%d", c);

} /* main */

int add(int x, int y) /* add is a function with return value to main */

{

/* Local definition */

int z;

/* Statements */

z=x+y;

return(z);

} /* add */

OUTPUT

Enter two numbers: 10 20

Result is ...30

EXPLANATION: The main() function calls and sends arguments to the user defined function add(). The add() function performs calculation and the values are returned back to the main function through the return() function. The reading and writing the values are done in the main function.


Computer Programming C Laboratory: Functions C Programs : Tag: C Programming : - C Program for addition of two numbers (Function with arguments and with return value)


Computer Programming C Laboratory: Functions C Programs



Under Subject



Related Subjects