欢迎光临散文网 会员登陆 & 注册

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

2023-07-01 10:13 作者:秦城淮海  | 我要投稿

//数组逆置



#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;

}

黑马程序员匠心之作|C++教程从0到1入门编程,学习编程不再难的评论 (共 条)

分享到微博请遵守国家法律