#include
int main()
{
int max=0,min=0,n,a[100]={1}; //max,min:最高、最低分所在的下标
printf("请输入学生的成绩,以负数表示结束:");
for(n=0;;n++)
{
scanf("%d",&a[n]);
if(a[n]<0)break;
if(a[n]>a[max])max=n;
if(a[n]
} //共有n个有效成绩 printf("最高分=%d\n",a[max]); printf("最低分=%d\n",a[min]); getch(); return 0; }
#include
int main()
{
float score,max,min;
score = max = min = 0;
printf("请输入学生成绩:");
scanf("%f",&score);
max = min = score;
while(score>=0)
{
scanf("%f",&score);
if(max < score)
{
max = score;
}
if(min > score && score>=0)
{
min = score;
}
}
printf("最高成绩:%g,最低成绩:%g\n",max,min);
}
看看吧!#include
using namespace std;void main()
{
double score=0,maxScore,minScore;
cin>>score;
maxScore=minScore=score;
while(score>=0)
{
cin>>score;
if (score<0)
{
break;
}
else
{
if (score
minScore=score;
}
if (score>maxScore)
{
maxScore=score;
}
}
}
if (maxScore<0||minScore<0)
{
cout<<"输入出错"<
else
cout<<"最高成绩"<