+ 1

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; }

22nd Apr 2021, 1:26 PM
reza
reza - avatar
2 odpowiedzi
+ 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"); }
22nd Apr 2021, 1:52 PM
Ipang
0
Ipang Thanks a lot
22nd Apr 2021, 1:55 PM
reza
reza - avatar