c program to demonstrate function without argument

//Function without argument c program

Function without arguments


Functions can be of two types.

2. Function without arguments

A function with arguments will have arguments or parameters passed along with it, eg- Sum(a,b), here a and b are the arguments passed along with the function Sum(). The values stored in a and b can be used for computations inside the Sum() function.
                                                            A function without arguments will not contain any arguments or parameters passed along with it, eg- Sum().

Explanation of the program 


This program creates a user defined function called add(). The function takes as input the values for three variables a, b and c. It then adds these three variables and assigns the result to a variable sum and the value stored in sum is returned from the function. The statement c=add(); calls the function and assigns the value returned from the function to the variable c. 

Program

#include<stdio.h>

#include<conio.h>

int add(void);

void main()

{

clrscr();

int c;

c=add();                      //function call

printf("Sum is %d",c);

getch();

}

int add(void)     //function definition

{

int a,b,c,sum;

printf("Enter three numbers");

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

sum=a+b+c;

return(sum);

}


Output

C program for function without arguments.
C program for function without arguments


No comments: