Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 比较c++;_C++ - Fatal编程技术网

C++ 比较c++;

C++ 比较c++;,c++,C++,我有两个整数数组 #include<iostream> using namespace std; int comparetwoarrays( int array1[], int array2[], int ARRAY_SIZE1, int ARRAY_SIZE2 ) int main () { int const ARRAY_SIZE = 500; int const ARRAY_SIZE = 10; int array1[ARRAY_SIZE];

我有两个整数数组

#include<iostream> 
using namespace std;
int comparetwoarrays( int array1[], int array2[], int ARRAY_SIZE1, int ARRAY_SIZE2 )

int main ()
{
    int const ARRAY_SIZE = 500;
    int const ARRAY_SIZE = 10;
    int array1[ARRAY_SIZE];
    int array2[ARRAY_SIZE2];
    comparetwoarrays( array1, array2, ARRAY_SIZE1, ARRAYSIZE2 )
}

int comparetwoarrays( int array1[], int array2[], int ARRAY_SIZE1, int ARRAY_SIZE2 )
{
    int holdsAlike[10] = {0};
    for( int g = 0; g < ARRAY_SIZE2; g++ )
    {
        for ( int t = 0; t < ARRAY_SIZE2; t++ )
        {
            if ( array2[g] == array1[t])
            {
                 holdsAlike[g] = array2[g];
                 cout<<holdsAlike[g];
            }
            for( int w = 0; w < ARRAY_SIZE2; w++ )
            {
                 if( holdsAlike[w] != 0 )
                 cout<<holdsAlike[w];
            }
        }
    }
#包括
使用名称空间std;
int CompareTowarray(int array1[],int array2[],int ARRAY_SIZE1,int ARRAY_SIZE2)
int main()
{
int const数组_SIZE=500;
int const数组_SIZE=10;
int array1[数组大小];
int array2[ARRAY_SIZE2];
比较阵列(阵列1、阵列2、阵列大小1、阵列大小2)
}
int CompareTowarray(int array1[],int array2[],int ARRAY_SIZE1,int ARRAY_SIZE2)
{
int holdsAlike[10]={0};
对于(int g=0;g无法编写所需的代码。可能是这样的:

#include <iostream>

using std::cout;

int comparetwoarrays( const int array1[], const int array2[], int array_size1, int array_size2 );

int main ()
{
    int const ARRAY_SIZE1 = 500;
    int const ARRAY_SIZE2 = 10;
    int array1[ARRAY_SIZE1] = {0};
    int array2[ARRAY_SIZE2] = {0};

    // set values to the arrays

    comparetwoarrays( array1, array2, 10, ARRAY_SIZE2 );
}

void comparetwoarrays( const int array1[], const int array2[], int array_size1, int array_size2 )
{
    for( int g = 0; g < array_size2; g++ )
    {
        for ( int t = 0; t < array_size1; t++ )
        {
            if ( array2[g] == array1[t])
            {
                if (g == t)
                {
                    cout << "got \"" << array2[g] << "\" at index " << g << "\n";
                }
                else
                {
                    cout << "got value = " << array2[g] << ", index on array2 = " << g <<", index on array1 = " << t << "\n";
                }
            }
        }
    }
}
#包括
使用std::cout;
int CompareTowarray(常数int array1[],常数int array2[],整数数组大小1,整数数组大小2);
int main()
{
int const数组_SIZE1=500;
int const数组_SIZE2=10;
int array1[ARRAY_SIZE1]={0};
int array2[ARRAY_SIZE2]={0};
//设置数组的值
比较阵列(阵列1、阵列2、阵列10、阵列大小2);
}
void comparetroarray(常量int数组1[],常量int数组2[],int数组大小1,int数组大小2)
{
对于(int g=0;g你能给数组大小下两个定义吗?我想其中一个应该是数组大小2。是的,我试着比较大数组和小数组的前10个元素。这看起来像是家庭作业。你的具体问题是什么?不是强制性的,但你会得到分数,而且我真的很想知道怎么做解决它。非常糟糕。对于每个数组1元素,数组2将其索引更改为0-9,直到数组1达到499…-。添加了比较前10个元素的代码。我试图创建一个比较两个数组的函数。它将比较数组2中的值和数组1中的前10个元素。并且,如果元素匹配ch,我希望它打印“get”以及值和索引。例如,如果两个数组的位置1包含相同的值,它将在索引1处打印“get”值。如果我要初始化两个不同数组的元素,它将工作。int main(){int const ARRAY_SIZE1=500;int const ARRAY_SIZE2=10;int array1[ARRAY_SIZE1]={0};int array2[ARRAY_SIZE2]={0};//为(int i=0;ivoid comparetwoarrays( const int array1[], const int array2[], int array_size1, int array_size2 )
{
    for( int g = 0; g < array_size1 && g < array_size2; g++ )
    {
        if ( array2[g] == array1[g])
        {
            cout << "got \"" << array2[g] << "\" at index " << g << "\n";
        }
    }
}