Advertisement
Niloy007

Array + Func

Feb 17th, 2021
718
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.58 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. // a[row][col]
  4.  
  5. int sum(int n) {
  6.     int res = 0;
  7.     for (int i = 1; i <= n; i++) {
  8.         res = res + i;
  9.     }
  10.     return res;
  11. }
  12.  
  13. int main() {
  14.     int n;
  15.     scanf("%d", &n);
  16.     int result = sum(n);
  17.     printf("%d\n", result);
  18. }
  19.  
  20. // int main() {
  21. //  int m, n;
  22. //  scanf("%d %d", &m, &n);
  23. //  int a[m][n];
  24. //  int i, j;
  25. //  // 1st part
  26. //  for (i = 0; i < m; i++) {
  27. //      for (j = 0; j < n; j++) {
  28. //          scanf("%d", &a[i][j]);
  29. //      }
  30. //  }
  31. //  printf("Row-wise: ");
  32. //  for (i = 0; i < m; i++) {
  33. //      for (j = 0; j < n; j++) {
  34. //          printf("%d ", a[i][j]);
  35. //      }
  36. //  }
  37. //  printf("\n");
  38. //  printf("Column-wise: ");
  39. //  // for (j = 0; j < n; j++) {
  40. //  //  for (i = 0; i < m; i++) {
  41. //  //      printf("%d ", a[i][j]);
  42. //  //  }
  43. //  // }
  44. //  // printf("\n");
  45.  
  46. //  // alternative
  47. //  for (i = 0; i < n; i++) {
  48. //      for (j = 0; j < m; j++) {
  49. //          printf("%d ", a[j][i]);
  50. //      }
  51. //  }
  52. //  printf("\n");
  53. // }
  54.  
  55. // int main() {
  56. //  int row, col;
  57. //  scanf("%d %d", &row, &col);
  58. //  int a[row][col];
  59. //  int i, j;
  60. //  for (i = 0; i < row; i++) {
  61. //      for (j = 0; j < col; j++) {
  62. //          scanf("%d", &a[i][j]);
  63. //      }
  64. //  }
  65.  
  66. //  for (i = 0; i < row; i++) {
  67. //      for (j = 0; j < col; j++) {
  68. //          printf("%d ", a[i][j]);
  69. //      }
  70. //      printf("\n");
  71. //  }
  72. // }
  73.  
  74. /*
  75.     Basics of 2D Array
  76.     -> 2D Array Printing
  77.     -> Problems
  78.         -> 21, 22, 24
  79. */
  80.  
  81. /*
  82. Test Case:
  83. Problem - 21:
  84. 9 8 7 6 5 4 3 2 1
  85.  
  86. 1 1 1 2 2 2 3 3 3
  87.  
  88. Problem - 22:
  89. 2 3
  90. 1 2 3
  91. 6 5 4
  92.  
  93. 3 3
  94. 1 1 1
  95. 2 2 2
  96. 3 3 3
  97.  
  98. Problem - 24:
  99.  
  100. 5
  101. 1 2 3 4 5
  102. 5 4 3 2 1
  103. 2 2 2 2 2
  104. 6 7 8 9 0
  105. 1 9 3 7 4
  106.  
  107.  
  108. */
  109.  
  110.  
  111.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement