close
Blogtrottr
Yahoo!奇摩知識+ - 分類問答 - 電腦網路 - 發問中
Yahoo!奇摩知識+ - 分類問答 - 電腦網路 - 發問中 
c++ 找最小的三個值
Mar 26th 2015, 02:06

如果用while迴圈做輸入和判斷,那麼一開始怎麼假設最小值,謝謝
這是我的程式碼
unsigned int counter;
int number,min1,min2,min3;
min1=0;
min2=0;
min3=0;
counter=1;
while (counter<=10)
{
printf("請輸入第%d個數字(不可重複):",counter);
scanf("%d",&number);
if(number<min1)
{
min3=min2;
min2=min1;
min1=number;
}
else if(number<min2)
{
min3=min2;
min2=number;
}
else if(number<min3)
{
min3=number;
}
counter += 1;
}
printf("最小的數字:%d\n",min1);
printf("第二小的數字:%d\n",min2);
printf("第三小的數字:%d\n",min3);
system("pause");

This entry passed through the Full-Text RSS service - if this is your content and you're reading it on someone else's site, please read the FAQ at fivefilters.org/content-only/faq.php#publishers.

You are receiving this email because you subscribed to this feed at blogtrottr.com.

If you no longer wish to receive these emails, you can unsubscribe from this feed, or manage all your subscriptions
arrow
arrow
    全站熱搜

    kkotgszvx368m 發表在 痞客邦 留言(0) 人氣()