首页 > 其他分享 >minimun value

minimun value

时间:2022-12-18 22:01:12浏览次数:30  
标签:--- int scanf value minimun while 输入

题目描述

Read a group of positive integers ending with a negative integer. Find out the minimum value among the positive integers and print the result.

样例输入

10 9 8 7 6 5 4 3 2 1 -1

样例输出

1


 1 #include<stdio.h>
 2 int main()
 3 {
 4     int a[50],i=0;
 5     while(1)
 6     {
 7         scanf("%d",&a[i]);
 8         if(a[i]<0)
 9             break;
10         i++;
11     }
12     for(int j=0;j<i-1;j++)
13     {
14         for(int k=0;k<i-1-j;k++)
15         {
16             if(a[k]>a[k+1])
17             {
18                 int tem=a[k];
19                 a[k]=a[k+1];
20                 a[k+1]=tem;
21             }
22         }
23     }
24     printf("%d",a[0]);
25 }

solution:

  当输入为负数时结束输入:

    1 while(a>=0)

      scanf("%d",&a); ---输入负数时程序的输入并没有中断

    2 while(scanf("%d",&a)>0)   ---结果同上

    3 while(1)

      scanf("%d",&a[i]);

      if(a[i]<0)

        break;      ---程序运行正确

标签:---,int,scanf,value,minimun,while,输入
From: https://www.cnblogs.com/luoxiaoluo/p/16991040.html

相关文章