Answers for "how to get input in 2d array in c"

C
0

create 2d array take input form user and write a display fuction to display in array format in c

#include<stdio.h>
int main(){
   /* 2D array declaration*/
   int disp[2][3];
   /*Counter variables for the loop*/
   int i, j;
   for(i=0; i<2; i++) {
      for(j=0;j<3;j++) {
         printf("Enter value for disp[%d][%d]:", i, j);
         scanf("%d", &disp[i][j]);
      }
   }
   //Displaying array elements
   printf("Two Dimensional array elements:\n");
   for(i=0; i<2; i++) {
      for(j=0;j<3;j++) {
         printf("%d ", disp[i][j]);
         if(j==2){
            printf("\n");
         }
      }
   }
   return 0;
}
Posted by: Guest on June-17-2021
0

how to get input in 2d array in c

#include <stdio.h>

int main(){

    printf("Enter the number of columns");
    int i; 
    scanf("%d", &i);
    printf("Enter the number of rows");
    int y; 
    scanf("%d", &y);

    int r[i][y];
    int a;
    int b;

        for (a=0; a<i; a++){
            for (b=0; b<y; b++){
    scanf("%d",&r[a][b]);
        }
    }
}
Posted by: Guest on November-19-2020
2

double array in c

int disp[2][4] = {
    {10, 11, 12, 13},
    {14, 15, 16, 17}
};
Posted by: Guest on June-21-2020

Code answers related to "C"

Browse Popular Code Answers by Language