Thread: problem in two dimentional array

  1. #1
    Registered User
    Join Date
    Jul 2012
    Posts
    1

    Question problem in two dimentional array

    hello guys, i've got some problems in 2d array:
    1)here i've declared i=5 and j=4, therefore it must take only 9 inputs from me but it's taking 10 inputs
    2)can't figure out why it is not printing the numbers entered in the array
    Code:
    #include<stdio.h>
    #include<conio.h>
    main()
    {
     int i,j;
     int array[5][4];
     clrscr();
     printf(" Enter i and j : ");
     for(i=0;i<5;i++)
    {
     for(j=0;j<4;j++);
    {
     scanf("%d%d",&array[i][j]);
    }
    }
    printf(" Output = %d%d",array[i][j]);
    getch();
    return 0;
    }
    can't figure out what's wrong
    thanks in adv.
    have a nice day

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > 1)here i've declared i=5 and j=4, therefore it must take only 9 inputs from me but it's taking 10 inputs
    It's a 2D array, so there should be 5*4 (ie, 20) inputs!

    > for(j=0;j<4;j++);
    The ; at the end means do nothing.

    > printf(" Output = %d%d",array[i][j]);
    You tried to print two values, but supplied only one parameter.

    To print the whole array, you need another pair of nested for loops - like the ones you used to scanf in all the values.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jun 2012
    Posts
    21
    the correct code:
    Code:
    scanf("%d",&array[i][j]);
    printf(" Output = %d",array[i][j]);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer to two dimentional array
    By lio in forum C Programming
    Replies: 2
    Last Post: 11-06-2010, 10:55 AM
  2. 3 dimentional array in C
    By jahanpanah in forum C Programming
    Replies: 3
    Last Post: 10-24-2010, 11:16 AM
  3. 2 dimentional array
    By theone1 in forum C++ Programming
    Replies: 10
    Last Post: 11-11-2007, 01:30 PM
  4. Two dimentional array
    By h3ro in forum C++ Programming
    Replies: 12
    Last Post: 04-17-2007, 01:01 AM
  5. Pointer to 2-dimentional array
    By thone in forum C Programming
    Replies: 5
    Last Post: 09-18-2004, 08:17 AM