fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int n, i, key, count = 0;
  5. printf("Enter the size of the array: ");
  6. scanf("%d", &n);
  7.  
  8. int arr[n];
  9. printf("Enter %d elements of the array:\n", n);
  10. for (i = 0; i < n; i++) {
  11. scanf("%d", &arr[i]);
  12. }
  13.  
  14. printf("Enter the number to count: ");
  15. scanf("%d", &key);
  16.  
  17. for (i = 0; i < n; i++) {
  18. if (arr[i] == key) {
  19. count++;
  20. }
  21. }
  22.  
  23. printf("The number %d occurs %d times in the array.\n", key, count);
  24. return 0;
  25. }
  26.  
Success #stdin #stdout 0s 5288KB
stdin
7
1 2 3 3 4 1 1
1
stdout
Enter the size of the array: Enter 7 elements of the array:
Enter the number to count: The number 1 occurs 3 times in the array.