합, 평균, 최댓값, 최솟값
// 작성자 : 김준현
// 작성일 : 2017-04-05
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# define L 3
# define large_ope(a, b) a>=b?a:b
# define small_ope(a, b) a<=b?a:b
typedef struct NUM
{
signed int num[L];
signed int large; // 최대값
signed int small; // 최소값
signed int sum; // 합계
double ave; // 평균
}NUM, *PTR_NUM;
// 1
PTR_NUM func_start();
// 2
void func_insert(NUM** n);
// 3
void func_sum(NUM** n);
// 4
void func_average(NUM** n);
//5
void func_large(NUM** n);
//6
void func_small(NUM** n);
int main(void)
{
PTR_NUM start = NULL;
start = func_start();
func_insert(&start);
func_sum(&start);
func_average(&start);
func_large(&start);
func_small(&start);
free(start);
return 0;
} // end of main function
// 1
PTR_NUM func_start()
{
PTR_NUM p = (PTR_NUM)malloc(sizeof(NUM));
if (p == NULL)
{
exit(1);
}
else
{
memset(p, 0, sizeof(NUM));
return p;
}
} // end of func_start function
// 2
void func_insert(NUM** n)
{
int i; // index
for (i = 0; i < L; i++)
{
printf("[%d] data : ", i+1);
scanf("%d", &((*n)->num[i]));
}
} // end of func_insert function
// 3
void func_sum(NUM** n)
{
int i; // index
for (i = 0; i < L; i++)
{
(** n).sum += (**n).num[i];
}
printf("Total sum => %d \n", (** n).sum);
} // end of func_sum function
// 4
void func_average(NUM** n)
{
(** n).ave = (** n).sum / L;
printf("ave => %.2lf \n", (** n).ave);
} // end of func_average function
// 5
void func_large(NUM** n)
{
(** n).large = large_ope((** n).num[0], (** n).num[1]);
(** n).large = large_ope((** n).large, (** n).num[2]);
printf("large => %d \n", (** n).large);
} // end of func_large function
// 6
void func_small(NUM** n)
{
(** n).small = small_ope((** n).num[0], (** n).num[1]);
(** n).small = small_ope((** n).small, (** n).num[2]);
printf("small => %d \n", (** n).small);
} // end of func_small function
'언어 > c언어' 카테고리의 다른 글
버퍼 비우는 귀여운 기술 (0) | 2017.04.29 |
---|---|
c언어 초보 : 대문자 => 소문자 (0) | 2017.04.09 |
자료구조 덱 (0) | 2017.04.02 |
이중 원형 연결 리스트 (0) | 2017.03.26 |
회문 (0) | 2017.02.09 |