fork(2) download
  1. #include<stdio.h>
  2.  
  3.  
  4. int c_array(int *a,int row,int column,int i,int j)
  5. {
  6. printf("%d ",*( a + i*column +j ) );//使用pointer來控制矩陣
  7. }
  8.  
  9.  
  10. int main(void)
  11. {
  12. int **ptr=NULL;
  13. int row,column;
  14. int i,j;
  15.  
  16. while(1)
  17. {
  18. printf("row=\n");
  19. scanf("%d",&row);
  20. printf("column=\n");
  21. scanf("%d",&column);
  22.  
  23. if(row==0 && column==0) break;
  24.  
  25.  
  26.  
  27. ptr=(int**)malloc(sizeof(int*)*row);
  28. //生成一維指標陣列
  29. for(i=0;i<row;i++)
  30. {
  31. ptr[i]=(int*)malloc(sizeof(int)*column);
  32. }//二維
  33.  
  34. for(i=0;i<row;i++)
  35. {
  36. for(j=0;j<column;j++)
  37. {
  38. ptr[i][j]=1;
  39. }
  40. }//將矩陣付值:1
  41.  
  42. for(i=0;i<row;i++)
  43. {
  44. for(j=0;j<column;j++)
  45. {
  46. //printf("%d",ptr[i][j]);//測試用
  47. c_array((int*)ptr,row,column,i,j);//使用另外函數來print
  48. }
  49.  
  50. printf("\n");//換行
  51. }
  52.  
  53. for(i=0;i<row;i++) free(ptr[i]);
  54. free(ptr);//釋放記憶體
  55.  
  56. }
  57.  
  58. return 0;
  59.  
  60.  
  61.  
  62. }
  63.  
Time limit exceeded #stdin #stdout 5s 528384KB
stdin
Standard input is empty
stdout
Standard output is empty