fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #define N 100
  5. int main()
  6. {
  7. int m, n, i, j, sum=0, x ;
  8. char ch;
  9. int A[N][N], B[N];
  10. printf("Enter m: \n");
  11. scanf("%d", &m);
  12. printf("Enter n:\n");
  13. scanf("%d", &n);
  14. srand(time(NULL));
  15. printf("use random values:Y/N \n");
  16. scanf("%c", &ch);scanf("%c", &ch);
  17. if(ch=='Y'){
  18. for (i=0; i<m; i++){
  19. printf("\n");
  20. for(j=0; j<n; j++ ){
  21. A[i][j]=rand()%100;
  22. printf(" %d ", A[i][j]);
  23. }
  24. }
  25. }
  26. else{
  27. printf("\nInput elements of array:\n");
  28. for(i = 0; i < m; i++){
  29. for(j = 0; j < n; j++){
  30. printf("Input A[%d][%d] = ", i, j);
  31. scanf("%d", &A[i][j]);
  32. }
  33. }
  34. }
  35. printf(" \nYour matrix:\n");
  36. for( i = 0; i<m; i++){
  37. for(j = 0; j<n; j++){
  38. printf("%d ", A[i][j]);
  39. if(j==n-1){
  40. printf("\n");
  41. }
  42. }
  43. }
  44. for (i = 0; i < m; ++i)
  45. {
  46. for (j = 0; j < n; ++j)
  47. {
  48. sum = sum + A[i][j] ;
  49. }
  50.  
  51. printf("\nSum of the %d row is = %d\n", i, sum);
  52. sum=0;
  53. }
  54. sum=B[i];
  55. for(i=0; i<n-1; i++){
  56. if(B[i]<B[i+1]){
  57. x=B[i];
  58. B[i]=B[i+1];
  59. B[i+1]=x;
  60. }
  61. for(j=0; j<n; j++){
  62. x=A[i][j];
  63. A[i][j]=A[i+1][j];
  64. A[i+1][j]=x;
  65. }
  66. }
  67.  
  68. printf("\nYour matrix:\n");
  69. for( i = 0; i<n; i++){
  70. for(j = 0; j<n; j++){
  71. printf(" %5d ", A[i][j]);
  72. if(j==n-1){
  73. printf("\n");
  74. }
  75. }
  76. }
  77. }
Success #stdin #stdout 0s 5348KB
stdin
Standard input is empty
stdout
Enter m: 
Enter n:
use random values:Y/N 

Input elements of array:
 
Your matrix:

Your matrix: