C 求最大值和最小值问题

版权声明:转载请附上文章地址 https://blog.csdn.net/weixin_38134491/article/details/85254182

问题:

Write a program that reads in five integers

and then determines and prints the largest and the smallest integers in the group.

#include<stdio.h>
#include<stdlib.h>

int main(void) {
	int max, min, n;
	printf("Input 5 integers:");
	for (int i = 1; i <= 5; i++) {
		scanf_s("%d", &n);

		if (i == 1) {
			max = n;
			min = n;
		}
		else {
			if (max < n) max = n;
			if (min > n) min = n;
		}

	}
	   
	printf("the largest value is %d\n", max);
	printf("the smallest value is %d\n", min);
	system("pause");
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_38134491/article/details/85254182