<method 1>
for(i=0;i<7;i++)cin>>a[i];
for(i=0;i<6;i++){
for(j=0;j<6-i;j++){
if(a[j]<a[j+1]){
b=a[j+1];
a[j+1]=a[j];
a[j]=b;
}
}
}
for(i=0;i<7;i++)cout<<a[i]<<endl;
<method 2>
int a[7],i,j,b;
for(i=0;i<7;i++)cin>>a[i];
for(i=0;i<7;i++){
for(j=i;j<7;j++){
if(a[i]<a[j]){
b=a[j];
a[j]=a[i];
a[i]=b;
}
}
}
for(i=0;i<7;i++)cout<<a[i]<<endl;
if you want to make an ascending order, just alter this part into that.
if(a[j]<a[j+1]) ---------> if(a[j]>a[j+1])
if(a[i]<a[j]) ---------> if(a[i]>a[j])
댓글
댓글 쓰기