fork download
  1. #include <stdio.h>
  2.  
  3. void bubbleSort(int arr[], int n) {
  4. int i, j, temp;
  5. for (i = 0; i < n - 1; i++) {
  6. for (j = 0; j < n - i - 1; j++) {
  7. if (arr[j] > arr[j + 1]) {
  8. temp = arr[j];
  9. arr[j] = arr[j + 1];
  10. arr[j + 1] = temp;
  11. }
  12. }
  13. }
  14. }
  15.  
  16. int main() {
  17. int n;
  18. printf("Enter the size of the array: ");
  19. scanf("%d", &n);
  20.  
  21. int a[n], b[n], count = 0;
  22. printf("Enter the elements of the array: ");
  23. for (int i = 0; i < n; i++) {
  24. scanf("%d", &a[i]);
  25. if (a[i] > 0 && a[i] % 3 == 0) {
  26. b[count] = a[i];
  27. count++;
  28. }
  29. }
  30.  
  31. bubbleSort(b, count);
  32.  
  33. int prev = b[0];
  34. int sameCount = 1;
  35. for (int i = 1; i < count; i++) {
  36. if (b[i] == prev) {
  37. sameCount++;
  38. } else {
  39. prev = b[i];
  40. }
  41. }
  42.  
  43. printf("Number of similar elements: %d\n", sameCount);
  44.  
  45. return 0;
  46. }
Success #stdin #stdout 0s 5308KB
stdin
2 2 4 5 4 
5
stdout
Enter the size of the array: Enter the elements of the array: Number of similar elements: 1