array in array | Sololearn: Learn to code for FREE!

0

array in array

Hey guys i want to write a program to print 3 array in an array with use array of pointers #include <stdio.h> int main() { int arr1[3]; int arr2[5]; int arr3[2]; int *ARR[3]={arr1,arr2,arr3}; for(int i=0;i<3;i++) { scanf("%d",&arr1[i]); } printf("=============\n"); for(int i=0;i<5;i++) { scanf("%d",&arr2[i]); } printf("=============\n"); for(int i=0;i<2;i++) { scanf("%d",&arr3[i]); } printf("=============\n"); for(int i=0;i<3;i++) { for(int j=0;j<(i don't know what should i write heir);j++) { printf("%d ",ARR[i][j]); } printf("\n"); } return 0; }

c++ c

4/22/2021 1:26:59 PM

reza

2 Answers

New Answer

+3

One feasible way would be to use another array to contain info about each array's length, and make <j> loop run on those limits. for (int i = 0, index[3] = { 3, 5, 2 }; i < 3; i++) { for (int j = 0; j < index[i]; j++) { printf("%d ", ARR[i][j]); } printf("\n"); }

0

Ipang Thanks a lot