Search
 
SCRIPT & CODE EXAMPLE
 

C

2 dimensional array in c

#include<stdio.h>
int main(){
   /* 2D array declaration*/
   int abc[5][4];
   /*Counter variables for the loop*/
   int i, j;
   for(i=0; i<5; i++) {
      for(j=0;j<4;j++) {
         printf("Enter value for abc[%d][%d]:", i, j);
         scanf("%d", &abc[i][j]);
      }
   }
   return 0;
}
Comment

passing two dimensional array to function in c

#include <stdio.h>
#include <stdlib.h>

#define ROWS 3
#define COLS 2

void fun1(int **, int, int);

int main()
{
  int array_2D[ROWS][COLS] = { {1, 2}, {3, 4}, {5, 6} };
  int n = ROWS;
  int m = COLS;

  fun1(array_2D, n, m);

  return EXIT_SUCCESS;
}

void fun1(int **a, int n, int m)
{
  int i, j;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      printf("array[%d][%d]=%d
", i, j, a[i][j]);
    }
  }
}
Comment

passing two dimensional array to function in c

#include <stdio.h>
#include <stdlib.h>

#define ROWS 3
#define COLS 2

void fun1(int (*)[COLS], int);

int main()
{
  int array_2D[ROWS][COLS] = { {1, 2}, {3, 4}, {5, 6} };
  int rows = ROWS;

  /* works here because array_2d is still in scope and still an array */
  printf("MAIN: %zu
",sizeof(array_2D)/sizeof(array_2D[0]));

  fun1(array_2D, rows);

  return EXIT_SUCCESS;
}

void fun1(int (*a)[COLS], int rows)
{
  int i, j;
  int n, m;

  n = rows;
  /* Works, because that information is passed (as "COLS").
     It is also redundant because that value is known at compile time (in "COLS"). */
  m = (int) (sizeof(a[0])/sizeof(a[0][0]));
 
  /* Does not work here because the "decay" in "pointer decay" is meant
     literally--information is lost. */
  printf("FUN1: %zu
",sizeof(a)/sizeof(a[0]));

  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      printf("array[%d][%d]=%d
", i, j, a[i][j]);
    }
  }
}
Comment

2d array in c

#include <stdio.h>
int main(){
    int scores[3][3],i,j;
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            printf("a[%d][%d] = ",i,j);
            scanf("%d",&scores[i][j]);
        }
    }

printf("
 Matrix view: 
");
for (i=0;i<3;i++)
{
    for (j=0;j<3;j++){
        printf("%d	",scores[i][j]);
    }
    printf("
");
}
}
Comment

2D Array In C

// Array of size n * m, where n may not equal m
for(j = 0; j < n; j++)
{
    for(i = 0; i < m; i++)
    {  
        array[i][j] = 0;
    }
}
Comment

PREVIOUS NEXT
Code Example
C :: bootstrap form 
C :: volatile keyword in c 
C :: simple bootstrap form example 
C :: c pointers 
C :: delete string function in c 
C :: check if pid exists c 
C :: fibonacci series in c 
C :: sort names in array in c 
C :: how to get the lowest number on a array in c 
C :: converting strings to numbers in c 
C :: what is c 
C :: c program for swapping of two numbers 
C :: pygramid program in c 
C :: Initialization of a 3d array in c 
C :: delay in c programming for linux 
C :: c structure with pointer 
C :: Create the static library libmy.a containing all the functions listed below: 
C :: Compile multiple C files 
C :: %= in c 
C :: c programming programiz 
C :: north austin weather 
C :: pathlib exclude hidden file 
C :: c to c convertor 
C :: C Operator associativity 
C :: can torch light bring change in chemical reaction 
C :: error: invalid type for iteration variable ‘i’ #pragma omp parallel for 
C :: kleiner gleich zeichen MAC 
C :: Clearing The Input Buffer In C/C++ 
C :: determination data type in c 
C :: bash sed crop cut file line number 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =