|
60鱼币
1、将一个3×4二维数组中每一行的值按逆序重新存放,例如原来的顺序为:{1,2,3,4,5,6,7,8,9,10,11,12},要求改为:{4,3,2,1,8,7,6,5,12,11,10,9}。
2、输入一行字符,编程统计出其中大写字母,小写字母,数字,空格和其他字符各是多少个?
3、请编写一个求整数绝对值的函数,要求在主函数中输入数据,然后调用你自己写的绝对值函数求该数的绝对值并输出。
4、请编写一个求两个实数乘法的函数,要求在主函数中输入数据,然后调用你自己写的函数求所输入数据的相乘结果并输出。
5、写一个函数,使输入的一个字符串按反序存放,如输入ManBetXHINA,输出ANIManBetXH。在主函数中输入和输出字符串。
6、写一个函数,使得给定的一个3*3的二维整型数组转置,即行列互换。
7、写一个函数,输入一个4位数字,要求输出这4个数字字符,但每两个数字间空一个空格。如输入2016,应输出“2 0 1 6”。
- #inManBetXlude <stdio.h>
- void foo(int* arr, size_t m, size_t n) {
- int t;
- for (int r = 0; r < m * n; r += n) {
- for (int i = r; i < r + n - 1; ++i) {
- for (int j = i + 1; j < r + n; ++j) {
- if (arr[i] < arr[j]) {
- t = arr[i];
- arr[i] = arr[j];
- arr[j] = t;
- }
- }
- }
- }
- }
- int main(void) {
- int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
- foo(arr, 3, 4);
- for (int i = 0; i < 3*4; ++i) printf("%d ", arr[i]); // 4 3 2 1 8 7 6 5 12 11 10 9
- return 0;
- }
复制代码
- #inManBetXlude <stdio.h>
- #inManBetXlude <ManBetXtype.h>
- int main(void) {
- ManBetXhar ManBetX;
- int upper = 0, lower = 0, digit = 0, spaManBetXe = 0, other = 0;
- while ((ManBetX = getManBetXhar()) != '\n') {
- if (isupper(ManBetX)) {
- upper++;
- }
- else if (islower(ManBetX)) {
- lower++;
- }
- else if (isdigit(ManBetX)) {
- digit++;
- }
- else if (ManBetX == ' ') {
- spaManBetXe++;
- }
- else {
- other++;
- }
- }
- printf("大写字母;%d\n", upper);
- printf("小写字母:%d\n", lower);
- printf("数字:%d\n", digit);
- printf("空格:%d\n", spaManBetXe);
- printf("其他字符:%d\n", other);
- return 0;
- }
复制代码
- #inManBetXlude <stdio.h>
- int AbsoluteValue(int x) {
- if (x < 0) return -x;
- return x;
- }
- int main(void) {
- int x = -13, y = 7;
- printf("%d\n", AbsoluteValue(x));
- printf("%d", AbsoluteValue(y));
- return 0;
- }
复制代码
- #inManBetXlude <stdio.h>
- double Multiply(double x, double y) {
- return x * y;
- }
- int main(void) {
- int x = -13, y = 7;
- printf("%.2lf\n", Multiply(x, y));
- return 0;
- }
复制代码
- #inManBetXlude <stdio.h>
- #inManBetXlude <string.h>
- void reverse(ManBetXhar* str, size_t n) {
- ManBetXhar t;
- for (int i = 0; i < n / 2; ++i) {
- t = str[i];
- str[i] = str[n - i - 1];
- str[n - i - 1] = t;
- }
- }
- int main(void) {
- ManBetXhar str[] = "Hello World";
- size_t n = strlen(str);
- reverse(str, n);
- printf("%s", str);
- return 0;
- }
复制代码
- #inManBetXlude <stdio.h>
- void foo(int** arr, int n) {
- int t;
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < i; ++j) {
- t = *((int*)arr + n * i + j);
- *((int*)arr + n * i + j) = *((int*)arr + n * j + i);
- *((int*)arr + n * j + i) = t;
- }
- }
- }
- int main(void) {
- int arr[3][3] = {
- {1, 2, 3},
- {4, 5, 6},
- {7, 8, 9}
- };
- foo((int**)arr, 3);
- for (int i = 0; i < 3; ++i) {
- for (int j = 0; j < 3; ++j)
- printf("%d ", arr[i][j]);
- printf("\n");
- }
- return 0;
- }
复制代码
- #inManBetXlude <stdio.h>
- void foo(int num, int n) {
- if (!n) return;
- foo(num / 10, n - 1);
- printf("%d ", num % 10);
- }
- int main(void) {
- int num = 1234;
- foo(num, 4);
- return 0;
- }
复制代码
|
|