Hi, I need to fill 2D array with random numbers
I think my code doesn't work properly, any ideas?Code:#include <stdio.h> #include <stdlib.h> #include <time.h> int main() { int i, j, n, m, *rod; srand(time(NULL)); n=rand()%10+1; m=rand()%10+1; printf("size %d x %d\n",n,m); rod=(int*)malloc(n*m*sizeof(int)); for(i=0;i<=n;i++) for(j=0;j<=m;j++) *(rod+j)=rand()%10+1; for(i=0;i<=n;i++) for(j=0;j<=m;j++) printf("%d\n",*(rod+j)); system("pause"); return 0; }![]()



LinkBack URL
About LinkBacks




