Home »
C programs »
C user-defined functions programs
C - User-defined function example with no argument and no return type
User define function Example with No argument and No return type - In this C program, we are defining a function that will not have any argument and return type.
Submitted by IncludeHelp, on April 18, 2018
C program for user-defined function example with no argument and no return type
In the program, we have function named fun1 which has no argument and no return type (void is the return type - that means, function will not return anything).
Within the function fun1 we are declaring an array, calculating sum of its elements and printing the sum.
Source Code
/*
User define function example with no argument
and no return type
*/
#include <stdio.h>
void fun1(void)
{
int array[10]={1,2,3,4,5,6};
int i=0,sum=0;
for(i=0;i<6;i++)
{
sum = sum + array[i];
}
printf("\nThe sum of all array elements is : %d",sum);
}
// main function
int main()
{
//calling the function
fun1();
return 0;
}
Output
The sum of all array elements is : 21
C User-defined Functions Programs »