c語言 函數的參數傳遞示例
Define a function with no argument and no return type in C language.
用C語言定義一個沒有參數且沒有返回類型的函數。
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).
在程序中,我們有一個名為fun1的函數,它沒有參數,也沒有返回類型( void是返回類型-這意味著該函數將不返回任何內容)。
Within the function fun1 we are declaring an array, calculating sum of its elements and printing the sum.
在fun1函數中,我們聲明一個數組,計算其元素的總和并打印總和。
程序 (Program)
</ s> </ s> </ s>/*
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
翻譯自: https://www.includehelp.com/c-programs/user-define-function-example-with-no-argument-and-no-return-type.aspx
c語言 函數的參數傳遞示例