2012年12月7日 星期五

c++之找出最大與最小數與位置


#include<iostream>
#include<cstdlib>
using namespace std;

main()
    {int i, x[10]={10,11,13,15,20,26,50,52,59,60};
     int max,min,maxd,mind;
min=x[0];
max=x[0];
cout<<"有10,11,13,15,20,26,50,52,59,60十個數"<<endl;
for(i=0;i<10;i++)
   {
if(x[i]>=max)
       {
max=x[i];
maxd=i;
    }
         
if(x[i]<=min)
{
min=x[i];
mind=i;


}
 
}
cout<<"The biggest number is"<<" "<<max<<" "<<"at"<<" "<<maxd+1<<endl;
cout<<"The smallest number is"<<" "<<min<<" "<<"at"<<" "<<mind+1<<endl;




}

沒有留言:

張貼留言