有人知道为什么有的时候代码会变灰色吗,但是我的又可以运行出来,我Day33代码也是灰色的
- P91 例4-15 二维数组转置
测试:#include<iostream> using namespace std; //输出数组 void print1(int(*p)[3], int n) { cout << "原数组为:" << endl; for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) cout << p[i][j] << "\t"; cout << endl; } } void print2(int(*p)[4], int n) { cout << "转置后的数组为:" << endl; for (int j = 0; j < n; j++) { for (int i = 0; i < 4; i++) cout << p[j][i] << "\t"; cout << endl; } } //二位数组转置 void f(int p1[][3], int p2[][4]) { for (int i = 0; i < 4; i++) for (int j = 0; j < 3; j++) p2[j][i]=p1[i][j]; } int main() { int a1[4][3] = { {1,2,3},{4,5,6},{7,8,9},{10,11,12} }; int a2[3][4]; print1(a1, 4); f(a1, a2); print2(a2, 3); return 0; }
-
P92 例4-16空格后小写字母转大写
#include<iostream> using namespace std; void f(char *s) { for (int i = 0; s[i]; i++) if (s[i] == ' ' && s[i + 1] <= 'z' && s[i + 1] >= 'a') s[i + 1] -= 32; } int main() { char str[100]; cin.getline(str, 100); f(str); cout << "转化后的字符数组为:" << str << endl; return 0; }
测试: