-1

何度も試して、何度も考えた後.. 欲求不満の人のように感じます。私は皆さんからいくつかの提案を得るためにここにいます..

実際、各行と列の最大値を見つけようとしています。したがって、分割統治法を使用して、各行の最大値を見つけるための 2 つの別個の関数を作成し、それを引数として使用した行ベクトルに格納します。列ごとに。

void maxValuesR(int a[][cols], int rv[], int row)
void maxValuesC(int a[][cols], int cv[], int row)

問題: コードはコンパイルさえされていません。エラーがわかりません..助けてください..

私は本当にここであなたの助けが必要です!

コードは次のとおりです。

#include <iostream>
using namespace std;
const int rows = 2;     // Declared As Global Variable
const int cols = 3; // Declared As Global Variable

void getData(int arr[][cols], int rows)
{
    for(int i = 0; i < rows; i++)
    {
        for(int j = 0; j < cols; j++)
        {
            cout << "Enter Element: ";
            cin >> arr[i][j];
        }
    }

}

void printData(int a[][cols], int rows)
{
    for(int i = 0; i < rows; i++)
    {
        for(int j = 0; j < cols; j++)
        {
            cout << a[i][j] << "\t";
        }
        cout << endl;
    }
}

void print_single(int a[], int row)
{
    for(int i = 0; i < row; i++)
    {
        cout << a[i] << "\t";
    }
}

void maxValuesR(int a[][cols], int rv[], int row)
{   int foxi;
    for(int i = 0; i < row; i++)
    {
        foxi = a[i][0];
        for(int j = 0; j < cols; j++)
            {

                if(foxi < a[i][j])
                {
                    foxi = a[i][j];
                }
            }
            rv[i] = foxi;
    }
}

void maxValuesC(int a[][cols], int cv[], int row)
{
    int maxi;
    for(int i = 0; i < cols; i++)
    {
        maxi = a[0][i];
            for(int j = 0; j < row; j++)
            {

                if(maxi > a[j][i])
                {
                    maxi = a[j][[i];// show error here => expected a '{' introducing lambda body
                }
            }
            cv[i] = maxi;   
    }
}

int main()
{
    int rowVector[rows];
    int colVector[cols];
    int a[rows][cols];

    cout << "Fill Array_1. " << endl;
    getData(a, rows);

    cout << "Array_1." << "\n\n";
    printData(a, rows); cout << endl;

    maxValuesR(a, rowVector, rows);
    print_single(rowVector, rows);

    cout << "\n\n";

    maxValuesC(a, colVector, rows);
    print_single(colVector, rows);

    return 0;
}
4

1 に答える 1

1

コンパイル エラーを明確にするには:

  • インクルードを忘れました(またはここに書きませんでしたか?)#include <iostream>
  • cincoutおよびの名前空間を指定しませんでしたendl(それらはstd名前空間にあります)
  • ステートメントに余分な「[」がありました。a[j][[i]おそらく、書きたかったのでしょうa[j][i]

コンパイル コードは次のようになります。

#include <iostream>

const int rows = 2;     // Declared As Global Variable
const int cols = 3; // Declared As Global Variable

void getData(int arr[][cols], int rows)
{
    for(int i = 0; i < rows; i++)
    {
        for(int j = 0; j < cols; j++)
        {
            std::cout << "Enter Element: ";
            std::cin >> arr[i][j];
        }
    }

}

void printData(int a[][cols], int rows)
{
    for(int i = 0; i < rows; i++)
    {
        for(int j = 0; j < cols; j++)
        {
            std::cout << a[i][j] << "\t";
        }
        std::cout << std::endl;
    }
}

void print_single(int a[], int row)
{
    for(int i = 0; i < row; i++)
    {
        std::cout << a[i] << "\t";
    }
}

void maxValuesR(int a[][cols], int rv[], int row)
{   int foxi;
    for(int i = 0; i < row; i++)
    {
        foxi = a[i][0];
        for(int j = 0; j < cols; j++)
            {

                if(foxi < a[i][j])
                {
                    foxi = a[i][j];
                }
            }
            rv[i] = foxi;
    }
}

void maxValuesC(int a[][cols], int cv[], int row)
{
    int maxi;
    for(int i = 0; i < cols; i++)
    {
        maxi = a[0][i];
            for(int j = 0; j < row; j++)
            {

                if(maxi > a[j][i])
                {
                    maxi = a[j][i];
                }
            }
            cv[i] = maxi;   
    }
}

int main()
{
    int rowVector[rows];
    int colVector[cols];
    int a[rows][cols];

    std::cout << "Fill Array_1. " << std::endl;
    getData(a, rows);

    std::cout << "Array_1." << "\n\n";
    printData(a, rows);
    std::cout << std::endl;

    maxValuesR(a, rowVector, rows);
    print_single(rowVector, rows);

    std::cout << "\n\n";

    maxValuesC(a, colVector, rows);
    print_single(colVector, rows);

    return 0;
}

ただし、入力例を指定しなかったため(対応する期待される出力は言うまでもなく)、必要な出力が生成されるかどうかはわかりません...

于 2013-10-24T07:45:47.293 に答える