Edx1026
Edx1026
采纳率100%
2020-12-07 19:58

作业作业!!!望大佬帮下忙!!?

50
已采纳

使用CodeBlocks软件,使用c++回答,同时需要放出源程序代码 

(1)输入3个整数,按由小到大的顺序输出。(要求编写一函数,用指针变量作为函数参数)

(2) 输入10个整数,将其中最小的数与第一个数对换,把最大的数与最后一个数对换。(要求用指针处理)

(4)有n个整数,使前面各数顺序向后移m个位置,最后m个数变成最前面m个数,写一函数实现以上功能,在主函数中输入n个整数,并输出调整后的n个数。

(5)编写一函数,将一个3×3的整型矩阵转置。(要求用指向数组元素的指针变量实现)

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

6条回答

  • WuZian_CSU wu zi an 5月前

    1、

    #include<iostream>
    
    using namespace std;
    
    void sort(int* x, int* y, int* z);
    
    int main()
    {
    	int a, b, c;
    	int* i, * j, * k;
    
    	i = &a, j = &b, k = &c;
    
    	cin >> *i >> *j >> *k;
    
    	sort(i, j, k);
    
    	cout << *i << *j << *k;
    
    	return 0;
    }
    void sort(int* x, int* y, int* z)
    {
    	int t;
    	if (*x < *y) {
    		if (*y > * z) {
    			if (*x < *z) {
    				t = *y, * y = *z, * z = t;
    			}
    			else {
    				t = *x, * x = *z, * z = t;
    				t = *y, * y = *z, * z = t;
    			}
    		}
    	}
    	else {
    		if (*y > * z) {
    			t = *x, * x = *z, * z = t;
    		}
    		else {
    			if (*x < *z) {
    				t = *x, *x = *y, *y = t;
    			}
    			else {
    				t = *x, *x = *y, *y = t;
    				t = *y, *y = *z, *z = t;
    			}
    		}
    	}
    }
    点赞 2 评论 复制链接分享
  • WuZian_CSU wu zi an 5月前

    2、

    #include <iostream>
    
    using namespace std;
    
    void sort(int* s, int n);
    
    int main()
    {
        int * p = new int[10];
    
        for (int i = 0; i < 10; i++) {
            cin >> p[i];
        }
    
        sort(p, 10);
    
        for (int i = 0; i < 10; i++) {
            cout << p[i] <<" ";
        }
    
        return 0;
    }
    
    void sort(int* s, int n)
    {
        int* i, * j, * min, * max, t;
    
        i = s;
        min = s;
        for (int k = 1; k <= n; k++) {
            if (*min > * i) {
                min = i;
            }
            i++;
    
        }
        t = *min;
        *min = *s;
        *s = t;
    
        j = s;
        max = s;
        for (int k = 1; k <= n; k++) {
            if (*max < *j) {
                max = j;
            }
            j++;
        }
        j--;
        t = *max;
        *max = *j;
        *j = t;
    }
    点赞 1 评论 复制链接分享
  • Edx1026 Edx1026 5月前

    谢谢

    点赞 评论 复制链接分享
  • WuZian_CSU wu zi an 5月前

    4、

    #include<iostream>
    
    using namespace std;
    
    void trans(int *a, int x, int y);
    
    int main()
    {
        int a[3][3];
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                cin >> a[i][j];
            }
        }
    
        int* p = &a[0][0];
        trans(p, 3, 3);
    
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                cout << a[i][j] << " ";
            }
            cout << endl;
        }
    
        return 0;
    }
    
    void trans(int *a, int x, int y)
    {
        int t;
        for (int i = 0; i < x; i++) {
            for (int j = i; j < y; j++) {
                t = *(a + x * i + j);
                *(a + x * i + j) = *(a + y * j + i);
                *(a + y * j + i) = t;
            }
        }
    }
    点赞 评论 复制链接分享
  • WuZian_CSU wu zi an 5月前

    4、

    #include<iostream>
    
    using namespace std;
    
    void trans(int *a, int x, int y);
    
    int main()
    {
        int a[3][3];
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                cin >> a[i][j];
            }
        }
    
        int* p = &a[0][0];
        trans(p, 3, 3);
    
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                cout << a[i][j] << " ";
            }
            cout << endl;
        }
    
        return 0;
    }
    
    void trans(int *a, int x, int y)
    {
        int t;
        for (int i = 0; i < x; i++) {
            for (int j = i; j < y; j++) {
                t = *(a + x * i + j);
                *(a + x * i + j) = *(a + y * j + i);
                *(a + y * j + i) = t;
            }
        }
    }
    点赞 评论 复制链接分享
  • WuZian_CSU wu zi an 5月前

    3、

    #include<iostream>
    
    using namespace std;
    
    void move(int* a, int* b, int n, int m);
    
    int main()
    {
    	int n;
    	int m;
    	cin >> n;
    	cin >> m;
    
    	int* a = new int[n];
    	int* b = new int[n + m];
    
    	for (int i = 0; i < n; i++) {
    		cin >> a[i];
    	}
    
    	move(a, b, n, m);
    
    	for (int i = 0; i < n; i++) {
    		cout << b[i] << " ";
    	}
    
    	return 0;
    }
    
    void move(int *a, int *b,int n,int m) 
    {
    	for (int i = 0; i < (n - m); i++) {
    		b[i + m] = a[i];
    	}
    
    	for (int i = (n - m); i < n; i++) {
    		b[i - (n - m)] = a[i];
    	}
    }
    点赞 评论 复制链接分享

相关推荐