编程从键盘输入10个数,存放在数组中,试找出最大和最小得数所在得位置
来源:百度知道 编辑:UC知道 时间:2024/06/03 20:56:04
咋就这么多人求这么基本的问题捏……
C版本:
#include <stdio.h>
int main(){
int number[10], t, biggest = 0, smallest = 0;
printf("Please key in the numbers: \n");
for(t = 0; t < 10; t++) scanf("%d",&number[t]);
for(t = 0; t < 10; t++) if(number[t] > number[biggest]) biggest = t;
for(t = 0; t < 10; t++) if(number[t] < number[smallest]) smallest = t;
printf("The biggest number occurs at position %d.\n", biggest + 1);
printf("The smallest number occurs at position %d.\n", smallest + 1);
return 0;
}
Borland C V5.5编译通过。
Java版本:
import java.util.Scanner;
public class findExtreme{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int[] nums = new int[10];
int biggest = 0, smallest = 0;
System.out.println("Please key in the 10 integers:\n");
for (int t = 0; t < 10; t++) n