Jump to content

how this output could be like this...

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
noteeth

noteeth

    Newbie

  • Members
  • PipPip
  • 21 posts
Hola :) i try to analysis this code but at the end i confuse...hope some1 can help to crack it...tq...

// initializing multidimensional arrays and function

#include <stdio.h>


// function prototype

void printArray(int [][3]);


int main()

{

	// declare 3 array with initial values…

	int array1[2][3] = {{1,2,3},{4,5,6}},

	array2[2][3] = {{1,2,3},{4,5}},

array3[2][3] = {{1,2}, {4}};

printf(“Element values in array1 by row are: \n”);

// first time function call

printArray(array1);

printf(“\nElement values in array2 by row are: \n”);

	// second time function call

printArray(array2);

printf(“Element values in array3 by row are:\n”);

// third time function call

printArray(array3);

printf(“\nNOTICE THE DEFAULT VALUE 0…\n”); 

return 0;

}


// function definition, passing an array to function

void printArray(int a[][3])

{

       int I, j;

       // the outer for loop, read row by row…

       for(i = 0; i <= 1; i++)

       {

// the inner for loop, for every row, read column by column…

              for(j=0; j<=2; j++)

              {

                     printf(“[%d][%d] = %d “, i, j, a[i][j]);

              }

       printf(“\n”);

       }

}


here the output:

Elements values in array1 over by row are:
[0][0] = 1 [0][1] = 1 [0][2] = 1
[1][0] = 5 [1][1] = 5 [1][2] = 5

Elements values in array2 over by row are:
[0][0] = 1 [0][1] = 1 [0][2] = 1
[1][0] = 5 [1][1] = 5 [1][2] = 5

Elements values in array1 over by row are:
[0][0] = 1 [0][1] = 1 [0][2] = 1
[1][0] = 0 [1][1] = 0 [1][2] = 0

#2
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
What is it that is confusing you?

#3
manux

manux

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 234 posts
I don't know how you managed to get this output...
When I run it I get the normal output, but I changed one thing, "I" to "i" in your printArray function, which was needed for compilation anyways :confused: