黑马程序员匠心之作|C++教程从0到1入门编程,学习编程不再难

//数组逆置
#include <iostream>
#include<math.h>
int main(){
using namespace std;
int str[5]={300,650,220,200,70};
int k=0,a=0,b=sizeof(str)/sizeof(str[0])-1;
for(;a<b;a++){
k=str[a];
str[a]=str[b];
str[b]=k;
b--;}
//while(a<b){
// //max=str[i];
// k=str[a];
// str[a]=str[b];
// str[b]=k;
// a++;b--;
//
//
//}//a和b都改变了,a=2,b=2
cout<<"输出逆置后的a:"<<a<<endl;
cout<<"输出逆置后的b:"<<b<<endl;
cout<<"输出逆置后的数组:"<<endl;
for(a=0;a<sizeof(str)/sizeof(str[0]);a++)
cout<<str[a]<<endl;
system("pause");
return 0;
}