#include<stdio.h>
int main(){
//define 2 "useless numbers"
int a[3],max = 0, min = 1000000;
// give values of the array by one loop
for (int i=0;i<3;i++){
scanf("%d",&a[i]);
}
// give values to max & min
for (int i = 0;i <3;i++){
if (max <a[i]){
max = a[i];
}
if (min >a[i]){
min = a[i];
}
}
printf("The maximum number is : %d\n",max);
printf("The minimum number is : %d\n",min);
return 0;
}
- define 2 "useless numbers"
- give values of the array by one loop
- give values to
max&min
self-tries:
#include<stdio.h>
int main(){
//define 2 "useless numbers"
int a[3],max = 0, min = 1000000;
// give values of the array by one loop
for(int i = 0; i<3; i++){
scanf("%d",&a[i]);
}
// give values to `max` & `min`
for(int i =0; i<3; i++){
if (max < a[i]){
max = a[i];
}
if (min >a[i]) {
min = a[i];
}
}
printf("The maximum number is : %d\n",max);
printf("The minimum number is : %d\n",min);
return 0;
}

京公网安备 11010502036488号