fork download
  1. #include<stdio.h>
  2. int array2d(int x,int y,int matrix[x][y])
  3. {
  4. int sum=0;
  5. for (int i=0;i<x;i++)
  6. {
  7. for(int j=0;j<y;j++)
  8. {
  9. sum+=matrix[i][j];
  10. }
  11. }
  12. return sum;
  13.  
  14. }
  15. int main()
  16. {
  17. int x,y;
  18.  
  19. printf("Enter the num of rows and colums:\n");
  20. scanf("%d %d",&x,&y);
  21. int matrix[x][y];
  22. printf("Enter the values");
  23. for(int i=0;i<x;i++)
  24. {
  25. for(int j=0;j<y;j++)
  26. {
  27. scanf("%d",&matrix[i][j]);
  28. }
  29.  
  30. }
  31. printf("the sum = %d",array2d(x,y,matrix));
  32.  
  33.  
  34.  
  35. }
  36.  
Success #stdin #stdout 0s 5268KB
stdin
Standard input is empty
stdout
Enter the num of rows and colums:
Enter the valuesthe sum = 0