1. 程式人生 > >簡單程式的編寫2:統計最高成績和最低成績

簡單程式的編寫2:統計最高成績和最低成績

以下程式的功能是從鍵盤輸入若干個學生的成績,統計出最高成績和最低成績,當輸入負數時,結束輸入。

#include<iostream.h>
void main()
{
	int str[100],i,x,max,min;
	for(i=0;;i++)
	{
		cout<<"please input:\n";
		cin>>x;
		if(x<0)
			break;
		else str[i]=x;
	}
	min=str[0];
	max=str[0];
	while(i--)
	{
		if(max<=str[i])
			max=str[i];
		if(min>=str[i])
			min=str[i];
	}
	cout<<"the max:"<<max<<endl;
	cout<<"the min:"<<min<<endl;
}