-
二维数组一
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #include <iostream>
- using namespace std;
- int main( )
- {
- int i,j;
-
- int
- a[5][4]={{0,1},{4,5},{8,9},{12,13},{16,17}};
-
- cout<<"请输入 10个整数:"<<endl;
- for(i=0;i<5;++i)
- {
- for(j=2;j<4;++j)
- {
- cin>>a[i][j];
- }
- }
-
- cout<<"数组中的值为:"<<endl;
- for(i=0;i<5;++i)
- {
- for(j=0;j<4;++j)
- {
- cout<<a[i][j]<<'\t';
- if(j==3)
- cout<<endl;
- }
- }
-
- cout<<"现在将所有元素乘以 3倍";
- for(i=0;i<5;++i)
- {
- for(j=0;j<4;++j)
- {
- a[i][j]=3*a[i][j];
- }
- }
-
- cout<<"行序优先输出:"<<endl;
- for(i=0;i<5;++i)
- {
- for(j=0;j<4;++j)
- {
- cout<<a[i][j]<<'\t';
- if(j==3)
- cout<<endl;
- }
- }
-
- cout<<"列序优先输出:"<<endl;
- for(j=0;j<4;++j)
- {
- for(i=0;i<5;++i)
- {
- cout<<a[i][j]<<'\t';
- if(i==4)
- cout<<endl;
- }
- }
-
- cout<<"倒着输出:"<<endl;
- for(i=4;i>=0;--i)
- {
- for(j=3;j>=0;--j)
- {
- cout<<a[i][j]<<'\t';
- if(j==0)
- cout<<'\n';
- }
- }
-
- cout<<"数组中的偶数:"<<endl;
- for(i=0;i<5;++i)
- {
- for(j=0;j<4;++j)
- {
- if(a[i][j]%2==0)
- cout<<a[i][j]<<'\t';
- }
- }
-
- cout<<"行列下标之和为 3 的倍数的元素:"<<endl;
- for(i=0;i<5;++i)
- {
- for(j=0;j<4;++j)
- {
- if((i+j)%3==0)
- cout<<a[i][j]<<'\t';
- }
- }
- cout<<'\n';
- return 0;
- }
-
相关阅读:
关于sifari兼容性的一个问题
HTML标签的应用(新手)
HTML标签的应用(新手)
未完成的开锁动画演示
HTML标签的应用(新手)
HTML新手向
C++
STL之set
C++输入输出
提升一下逼格
-
原文地址:https://www.cnblogs.com/herizai/p/3073642.html
Copyright © 2020-2023
润新知