33,321
社区成员




#include <iostream>
using namespace std;
int main() {
int t;
int a[10] = {12, 45, 9, 99, 4, 52, 62, 45, 81, 10}; //initialization
for (int count = 0; count < 9; ++count) { // 计数器,用来控制比较次数
for (int i = 0; i <= 9-count; ++i) {
if(*(a+i) < *(a+i+1)) {
t = *(a+i); // change the value
*(a+i) = *(a+i+1);
*(a+i+1) = t;
}
}
}
for (int j = 0; j <= 9; ++j) { // output the result
cout << *(a+j) << endl;
}
}
#include <iostream>
if(!count)
{
max1 = num;
6
++count;
}
void main( void )
{
int num = 0,count = 0;
int max1 = 0,max2 = 0;
puts("input some digits(end of '.'):");
while( scanf("%d",&num) )
{
if(!count)
{
max1 = num;
++count;
}
if(max1 < num)//重点在这里
{
max2 = max1;
max1 = num;
}
puts("input some digits(end of '.'):");
}
printf("max1 = %d,max2 = %d\n",max2,max1);
system("pause");
}