taeyounkim LOG
pointer practice 2 (program to find the largest and smallest elements in an array) 본문
pointer practice 2 (program to find the largest and smallest elements in an array)
taeyounkim 2021. 7. 7. 22:23#include <stdio.h>
#define NUM 10
void max_min(int a[], int n, int *, int *); /*declare prototype of function*/
int main()
{
int array[NUM];
int big, small;
printf("Enter 10 numbers: ");
for(int i=0; i<NUM; i++){
scanf("%d", &array[i]); /*read the value by scanf, and save it into array[i]*/
}
max_min(array, NUM, &big, &small); /*max points to big, min points to small*/
printf("Maximum number is: %d\n", big);
printf("Minimum number is: %d", small);
return 0;
}
void max_min(int a[], int n, int *max, int *min) /*compare the numbers and sort out the max/min number*/
{
*max = *min = a[0];
for(int i=1; i<n; i++){
if (*max < a[i])
*max = a[i];
else if(*min > a[i])
*min = a[i];
}
}
'Career&Study > Coding Practice' 카테고리의 다른 글
pointer practice 4 (function to print bigger integer) (0) | 2021.07.08 |
---|---|
pointer practice 3 (function to swap numbers) (0) | 2021.07.08 |
pointer practice (decomposing fraction program) (0) | 2021.07.07 |
Program to display "SEVEN SEGMENT DISPLAY" (0) | 2021.07.06 |
Guessing a Number game codes (0) | 2021.07.05 |