Find the maximum value among 5 numbers. Hint: ① Define i, max, a[5] as int type, and initialize max=a[0]. ② Input an 5 integer array using scanf() function by loop. ③ Compare max with 5 elements in sequence, and if it is less than one of them, update max. ③ Print max. For example Input: Please enter 5 numbers: 10 6 15 4 8 Output: The maximum value is 15.
时间: 2024-03-08 16:51:11 浏览: 100
C语言编程-用函数求N个[10,60]上的整数中能被5整除的最大的数,如存在则返回这个最大值,如果不存在则返回0;
5星 · 资源好评率100%
Sure, here is the code in C language to find the maximum value among 5 numbers:
```c
#include <stdio.h>
int main() {
int i, max, a[5];
// input 5 numbers
printf("Please enter 5 numbers: ");
for(i=0; i<5; i++) {
scanf("%d", &a[i]);
}
// find the maximum value
max = a[0];
for(i=1; i<5; i++) {
if(a[i] > max) {
max = a[i];
}
}
// output the result
printf("The maximum value is %d.\n", max);
return 0;
}
```
You can copy and paste this code to a C file, and then compile and run it to see the result. Let me know if you have any other questions.
阅读全文