Function with no arguments and with return value - C Programming
Addition of two numbers.
/* Function with no arguments and with return value */
#include <stdio.h>
main()
{
int add(); /* Local definition */
c=add(); /* add is a function with no arguments */
printf("Results in ..%d", C);
} /* main */
int add()/* add is a function with return value */
{
/* Local definition */
int a,b,c;
/* Statements */
printf ("Enter two numbers: ");
scanf("%d %d", &a, &b);
c=a+b;
return (c);
} /* add */
OUTPUT
Enter two numbers: 10, 20
Result is …. 30
EXPLANATION: In the above program, the main function did not send any arguments to the user defined function add(). But the user defined function sending back some values to the main function. The variable a and b are read and executed in add() function but the result is returned back to the main function.
Computer Programming C Laboratory: Functions C Programs : Tag: C Programming : - C Program to addition of two numbers (Function with no arguments and with return value)