在这里插入代码片#include <stdio.h>
#include <stdlib.h>
#include<math.h>
int translate(char *s);
int a[10] = {3,34,2,425,1,425,242,5,6324,-5};
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int min,min2,i;//store min number in the array
if(a[0]>a[1])
{
min = a[1]; //initalizing min and min2 (初始化)
min2 = a[0];
}
else {
min = a[0];
min2 = a[1]; // assigning value for min and min2
}
for(i = 2;i<10;i++) //cycle.assign value of min to min2 if value of a[i] if less than min and assign value of a[i] to min(遇到比最小的还小的就更新min 和 min2)
{
if(a[i]<min)
{ min2 = min;
min = a[i];
}
else{
if(a[i]<min2)
{
min2 = a[i];
}
}
}
printf("%d %d",min,min2);
return 0;
}
数组最小两数的C语言代码
最新推荐文章于 2021-08-22 21:21:56 发布