output 2d array help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yasirassassin
    New Member
    • Nov 2011
    • 7

    output 2d array help

    hey dear i need help in printing 2d array i can take input from user but cannot out put it please help

    #include<iostre am>

    using namespace std;


    int main()
    {int i,j,john[2][3]={{1,2,3},{5,6, 7}};

    for(i=1;i<=2;i+ +){
    for(j=1;j<=3;j+ +){
    cout<<"input value of "<<i<<" and "<<j<<endl;
    cin>>john[i][j];

    }

    system("pause") ;
    return 0;
    }
  • whodgson
    Contributor
    • Jan 2007
    • 542

    #2
    Use the two loops again to cout<<john[i][j];
    also i`m rather surprised that the declaration under main() compiles.

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      Your loops need to start with 0 rather than 1. They need to stop < the array dimension. Remember, a [2] array has elements 0 and 1.

      Comment

      Working...