#include<stdio.h>
main()
{
int x,max;
printf("End -1 to end:\n");
do
{
printf("Enter x:");
scanf("%d",&x);
}
while(x<0&&x!=1);
max=x;
while(x!=1)
{
printf("Enter x:");
scanf("%d",&x);
if(x>0&&x>max)
max=x;//max始终存放大于零的值
}
if(max!=-1)
printf("max=%d\n",max);
}
当输入以下数据时:
24 -6 18 12 -9 45 12 42 -1
输出一下结果:
max=45