一个while循环找出第二大的值

#include <stdlib.h>
#include <stdio.h>




int main()
{
int a[10] = {0,1,66,3,4,5,80,7,8,9};
int ma = 0;
bool b = true;
int *p = a;
ma = *p;




int lab;




int* myend = a+10;


while (p != myend)
{
if (b)
{
if (ma < *p)
{
ma = *p;
}
p++;
}else
{
if (*p != ma && lab > ma - *p)
{
lab = ma - *p;
}
p--;
}


if (p == a+10)
{
myend = a;
p -=1;
lab = ma - a[0];
b = false;
}
}




printf("%d",ma-lab);


system("pause");
return 0;
}
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页