Count duplicates number in an array

#include <stdio.h> void main() { int numbers[50]; int n, temp, value, count; int i, j; //printf("Input the number of elements to be stored in the array :"); scanf("%d",&n); // printf("Input %d elements in the array :\n",n); for(i=0;i<n;i++) { //printf("element - %d : ",i); scanf("%d",&numbers[i]); } /*--------------------------Sort the array------------------------------------*/ for (i = 0; i < n; ++i) { for (j = i + 1; j < n; ++j) { if (numbers[i] > numbers[j]) { temp = numbers[i]; numbers[i] = numbers[j]; numbers[j] = temp; } } } /*------------------- find the elements are duplicate -------------------------*/ for (i = 0;i < n;) { value = numbers[i]; count = 0;//count for the number located at index i //----যেহেতু নাম্বারগুলো সাজানো আছে একই মানের নাম্বার গুলো পরপর থাকবে------------ //----সেহেতু নিচের লুপটি যতক্ষণ পর্যন্ত একই মান পাওয়া যায় তার জন্য চালানো হয়েছে এবং কাউন্টের মান বাড়ানো হয়েছে------- do { i++; count++; } while (i < n && numbers[i] == value); if (count > 1) printf("Element %d has been repeated %d times\n", value, count); } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.