#include <stdio.h>
void returnTotalAndAvg(int *arr, float *total, float *avg); //formal parameter
int main()
{
float total=0, avg=0;
int num_std=0, i=0;
printf("Put the number of students.\n");
scanf("%d", &num_std);
int arr[num_std]={0};
for(i=0; i<num_std; i++)
{
printf("Put the score of student num.%d.\n", i+1);
scanf("%d", &arr[i]);
returnTotalAndAvg (arr, &total, &avg);//argument
}
printf("Total is %f, average is %f", total, avg);
return 0;
}
void returnTotalAndAvg(int *arr, float *total, float *avg)//formal parameter
{
static int i=0;
*total=*total+*(arr+i);
*avg=*total/(i+1);
i++;
}
//argument is the exact data to send to funtion. for array, only array name.
//for pointer, ex)&value
//for value, write a value name ^^
void returnTotalAndAvg(int *arr, float *total, float *avg); //formal parameter
int main()
{
float total=0, avg=0;
int num_std=0, i=0;
printf("Put the number of students.\n");
scanf("%d", &num_std);
int arr[num_std]={0};
for(i=0; i<num_std; i++)
{
printf("Put the score of student num.%d.\n", i+1);
scanf("%d", &arr[i]);
returnTotalAndAvg (arr, &total, &avg);//argument
}
printf("Total is %f, average is %f", total, avg);
return 0;
}
void returnTotalAndAvg(int *arr, float *total, float *avg)//formal parameter
{
static int i=0;
*total=*total+*(arr+i);
*avg=*total/(i+1);
i++;
}
//argument is the exact data to send to funtion. for array, only array name.
//for pointer, ex)&value
//for value, write a value name ^^
댓글
댓글 쓰기