Advertisement
Niloy007

Array

Feb 14th, 2021
636
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.77 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3.  
  4. // Problem - 8
  5. int main() {
  6.     int n;
  7.     int flag = 1;
  8.     scanf("%d", &n);
  9.     int arr[n];
  10.     for (int i = 0; i < n; i++) {
  11.         scanf("%d", &arr[i]);
  12.     }
  13.     int choice;
  14.     scanf("%d", &choice);
  15.     int i;
  16.     for (i = 0; i < n; i++) {
  17.         if (arr[i] == choice) {
  18.             printf("FOUND at index position: %d\n", i);
  19.             flag = 0;
  20.         }
  21.     }
  22.     if (i == n && flag == 1) {
  23.         printf("NOT FOUND\n");
  24.     }
  25. }
  26.  
  27.  
  28. // Problem - 6
  29. // int main() {
  30. //  int n;
  31. //  scanf("%d", &n);
  32. //  int a[n];
  33. //  for (int i = 0; i < n; i++) {
  34. //      scanf("%d", &a[i]);
  35. //  }
  36. //  int max = a[0];
  37. //  int index = 0;
  38. //  for (int i = 1; i < n; i++) {
  39. //      if (a[i] > max) {
  40. //          max = a[i];
  41. //          index = i;
  42. //      }
  43. //  }
  44. //  printf("Max: %d, Index: %d\n", max, index);
  45. // }   
  46.  
  47.  
  48. // Problem 1
  49. // int main() {
  50. //  int size;
  51. //  scanf("%d", &size);
  52. //  int arr[size];
  53. //  for (int i = 0; i < size; i++) {
  54. //      scanf("%d", &arr[i]);
  55. //  }
  56.  
  57. //  for (int i = size - 1; i >= 0; i--) {
  58. //      printf("%d ", arr[i]);
  59. //  }
  60. //  printf("\n");
  61. // }
  62.  
  63.  
  64. // int main() {
  65. //  int arr[5];
  66. //  for (int i = 0; i < 5; i++) {
  67. //      scanf("%d", &arr[i]);
  68. //  }
  69. //  printf("Values:\n");
  70. //  for (int i = 0; i < 5; i++) {
  71. //      printf("%d ", arr[i]);
  72. //  }
  73. //  printf("\n");
  74. // }
  75.  
  76.  
  77. /*
  78.     Basics Of Array
  79.     -> Array Printing
  80.     -> Problems
  81.         -> 1, 6, 8
  82.  
  83.     Basics of 2D Array
  84.     -> 2D Array Printing
  85.     -> Problems
  86.         -> 21, 22, 24
  87. */
  88.  
  89. /*
  90. Test Case:
  91. Problem - 1:
  92. 5
  93. 1 2 3 4 5
  94.  
  95. 6
  96. 2 8 3 9 0 1
  97.  
  98. Problem - 6:
  99. 5
  100. 1 2 3 4 5
  101.  
  102. 6
  103. 2 8 3 9 0 1
  104.  
  105. Problem - 8:
  106. 8
  107. 7 8 1 3 2 6 4 3
  108. 3
  109.  
  110. 8
  111. 7 8 1 3 2 6 4 3
  112. 5
  113.  
  114.  
  115. Problem - 21:
  116. 9 8 7 6 5 4 3 2 1
  117.  
  118. 1 1 1 2 2 2 3 3 3
  119.  
  120. Problem - 22:
  121. 2 3
  122. 1 2 3
  123. 6 5 4
  124.  
  125. 3 3
  126. 1 1 1
  127. 2 2 2
  128. 3 3 3
  129.  
  130. Problem - 24:
  131.  
  132. 5
  133. 1 2 3 4 5
  134. 5 4 3 2 1
  135. 2 2 2 2 2
  136. 6 7 8 9 0
  137. 1 9 3 7 4
  138.  
  139.  
  140. */
  141.  
  142.  
  143.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement