Thread: Newbies about array

  1. #1
    Unregistered
    Guest

    Newbies about array

    Dear engineers

    I have problem about the array 3X4 that pulled my hair for almost a week. I did search help, books, exercises and some net resource but seem did not help much. Here is the question: how do I make computer to understand that is " My_array [i][j]" when i input data from key board and use cout to print out the matrix 3x4. Also my second cout is to list the largest value from that matrix. Please direct if i made any mistake. Any help or suggestion is greatly appreciated. Thanks in advance for reading this message. Here is my code and this is the best of my knowledge:

    #include <iostream.h>
    #include <iomanip.h>


    int main()
    {

    cout << "please enter three sets of five number!\n\n";

    double check_num = 0; // initialize num, array's row and col
    const int arrayrow = 3;
    const int arraycol = 5;


    int matrix[arrayrow][arraycol];

    for (int x = 0; x < arrayrow; x ++){
    for (int j = 0; j < arraycol; j++)
    cin >>matrix [x][j];

    if (check_num < matrix [x][j])
    check_num = matrix[x][j];
    cout << matrix[x][j]<<' ';
    cout << "The biggest number is: "<<check_num;
    cout << endl;
    }
    return 0;
    }

  2. #2
    Registered User ivandn's Avatar
    Join Date
    Oct 2001
    Posts
    49
    #include <iostream.h>
    #include <iomanip.h>

    int main()
    {
    cout << "please enter three sets of five number!\n\n";
    const int arrayrow = 3;
    const int arraycol = 5;

    int matrix[arrayrow][arraycol];
    for (int x = 0; x < arrayrow; x ++)
    for (int y = 0; y < arraycol; y++)
    cin >>matrix [x][y];

    int check_num = matrix[0][0];
    // initialize to first num

    for (x = 0; x < arrayrow; x ++)
    {
    for (y = 0; y < arraycol; y++)
    {
    cout << matrix[x][y] << " ";

    if (matrix[x][y] > check_num)
    check_num = matrix[x][y];
    }
    cout << endl;
    }

    cout << "The biggest number is: "<<check_num << endl;

    return 0;
    }
    Ivan

  3. #3
    Unregistered
    Guest

    Talking

    Ivan
    Thanks very much. It worked like a charm. I have change the x and y from the loop of finding the biggest number because compiler said there are duplicated in initialize's name. I am wondering if your system are different from mine (pc-win 2000 professional)

    #include <iostream.h>
    #include <iomanip.h>

    int main()
    {
    cout << "please enter three sets of five number!\n\n";
    const int arrayrow = 3;
    const int arraycol = 5;

    int matrix[arrayrow][arraycol];
    for (int x = 0; x < arrayrow; x ++)
    for (int y = 0; y < arraycol; y++)
    cin >>matrix [x][y];

    int check_num = matrix[0][0]; // initialize to first num

    for ( int e = 0; e < arrayrow; e ++)
    {
    for ( int d= 0; d< arraycol; d++)
    {
    cout << matrix[e][d] << " ";

    if (matrix[e][d] > check_num)
    check_num = matrix[e][d];
    }
    cout << endl;
    }

    cout << "The biggest number is: "<<check_num << endl;

    return 0;
    }

    Moreover, I am wondering what is the different from ' ' and " ". I saw some example of c++ works just fine with the space of ' ' but in my case it did not work at all !!!. Once again thanks a bunch for your respond.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. from 2D array to 1D array
    By cfdprogrammer in forum C Programming
    Replies: 17
    Last Post: 03-24-2009, 10:33 AM
  3. Replies: 6
    Last Post: 11-09-2006, 03:28 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM