/*C語言 指標函數計算矩形*/
#include<stdio.h>
#include<stdlib.h>
void function(int, int, int *, int *);
//宣告函數function()接收四個引值
int main(void)
{
int length = 3, width = 4;
int area = 0, perimeter = 0;
printf("計算前length = %d, width = %d, area = %d, perimeter = %d\n",
length, width, area, perimeter);
function(length, width, &area, &perimeter);
printf("計算後length = %d, width = %d, area = %d, perimeter = %d\n",
length, width, area, perimeter);
system("pause");
return 0;
}
void function(int length, int width, int *area, int *perimeter)
{
*area = length * width;
//計算面積
*perimeter = 2 * length + 2 * width;
//計算周長
}
結果為:
文章標籤
全站熱搜
留言列表