c语言中如何返回一个数组函数


#include <iostream>

using namespace std;
int ac1(int a,int b){
    int maxx,minn;
    maxx=a>b?a:b;
    minn=a<b?a:b;
    if(maxx%minn==0){
        return minn;
    }
    else return ac1(minn,maxx%minn);
}
int * ac(int x,int y,int a[2]);

int main()
{
    int s[2]={0};
    int a,b;
    cin>>a>>b;
    int *p;
    p=ac(a,b,s);
    cout<<ac1(a,b)<<endl;
    cout<<p[0]<<" "<<p[1]<<endl;
    return 0;
}
int * ac(int x,int y,int a[2]){
    int num=ac1(x,y);
    int num2=x*y/num;
    a[0]=num;
    a[1]=num2;
    return a;
}
/*
 //通过返回传入数组的指针的方式
#include"stdio.h"
#include<iostream>
using namespace std;
//定义指针函数
int *copy(int array[], int a[], int n);
int main(){
    int size = 4;
    int a2[4];
    int a1[4] = {3, 5, 7 ,8};
    int *p;
    p = copy(a1, a2, size);
    cout << p[0] << " " << p[1] << " "<<p[2] << " " << p[3] << endl;
    return 0;
}
int *copy(int array[], int a[], int n)
{
    for(int i = 0; i < n; i++)
        a[i] = array[i];
    return a;
}*/

阅读更多
版权声明:emmmmm喵喵喵 https://blog.csdn.net/MallowFlower/article/details/80344957
个人分类: 水题
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭