Skip to main content

C program to print all repeated elements in an array and also print the count of repeated numbers

 Write a program to print all repeated elements in an array and also print the count of repeated numbers

Note: Hope it helps you! Please note that all the intentions are to clear the doubt of how to solve it in java. So, please try to give it a chance at least before using this. If you face any discrepancy please contact us. Thank you!

Example:

input:
Enter the number of element: 4
Enter Elements: 10
20
10
20
output:
The duplicate number is: 10
The duplicate number is: 20
The total number of the duplicate element is: 2

Algorithm of this program:
  1. Initially, we define the size of the array.
  2. Then, take a user-input size of the array and scan the element of the array.
  3. For finding the duplicate number in the array we have to run two for loops.
  4. The first for loop scan all elements from 0 index
  5. The next for loops run from i+1 so that it checks all the duplicate elements.
  6. If any duplicate element is found, we print the duplicate number and count it.
  7. At last, we print the count of all the duplicate numbers present in the array.
  8. The return type of the main function is int so, in the last, we return 0.

Program of the problem:

//Write a program to print all repeated elements in an array and also print the count of //repeated numbers
#include <stdio.h>
#define SIZE 100  
int main(){
    int arr[SIZE];
    int size;
    int count = 0;
    printf("Enter the number of elements in array: ");
    scanf("%d", &size);
    printf("Enter the value of elements in array: ");
    for(int i=0; i<size; i++){
        scanf("%d", &arr[i]);
    }
    for(int i=0; i<size; i++){
        for(int j=i+1; j<size; j++){
            if(arr[i] == arr[j]){
                printf("The duplicate numbers is: %d\n", arr[i]);
                count++;
                break;
            }
        }
    }
    printf("\nTotal number of duplicate elements found in array = %d", count);
    return 0;
}
//code is contributed by paagalblogger.blogspot.com

Output:
output of above program



Hope! it helps ๐Ÿ™


Comments

Post a Comment

Popular posts from this blog

GOD! a Thought, a Helping hand, or a Myth? (Hindi & English)

  GOD! a Thought, a Helping hand, or a Myth? Hello friends! Today we are going to talk about God. Do you think God is a thought, a helping hand or a myth?  When we talk about God, in our knowledge he is our master who knows everything and can do everything. They help us, relieve us from our troubles and also improve our health. According to the experiences of many of his devotees, God is very important in our life and helps us with our problems.   เคนेเคฒो เคฆोเคธ्เคคों! เค†เคœ เคนเคฎ เคฌाเคค เค•เคฐเคจे เคตाเคฒे เคนैं เคญเค—เคตाเคจ เค•े เคฌाเคฐे เคฎें। เค•्เคฏा เค†เคชเค•ो เคฒเค—เคคा เคนै เค•ि เคญเค—เคตाเคจ เคเค• เคธोเคš, เคเค• เคฎเคฆเคฆเค—ाเคฐ เคนाเคฅ เคฏा เคเค• เคฎिเคฅเค• เคนै? เคฎैंเคจे เค…เคชเคจे เคœीเคตเคจ เคฎें เคญเค—เคตाเคจ เคธे เคฌเคนुเคค เคธे เคฒोเค—ों เค•ो เคฎिเคฒा เคนै, เค”เคฐ เค‰เคจเคฎें เคธे เคนเคฐ เคเค• เค•ा เคญเค—เคตाเคจ เค•े เคฌाเคฐे เคฎें เค…เคฒเค—-เค…เคฒเค— เคตिเคšाเคฐ เคนै। เค•ुเค› เคฒोเค— เคฎाเคจเคคे เคนैं เค•ि เคญเค—เคตाเคจ เคเค• เคธोเคš เคนै, เคœिเคธเค•ी เคฎเคฆเคฆ เคธे เคนเคฎ เค…เคชเคจी เคœिंเคฆเค—ी เคฎें เคธुเคงाเคฐ เคฒा เคธเค•เคคे เคนैं। เค…เคจ्เคฏ เคฒोเค— เคฎाเคจเคคे เคนैं เค•ि เคญเค—เคตाเคจ เคเค• เคฎเคฆเคฆเค—ाเคฐ เคนाเคฅ เคนै, เคœो เคนเคฎाเคฐी เคธเคฎเคธ्เคฏाเค“ं เค•ो เคนเคฒ เค•เคฐเคจे เคฎें เคนเคฎाเคฐी เคฎเคฆเคฆ เค•เคฐเคคा เคนै। เคนाเคฒांเค•ि, เค•ुเค› เคฒोเค— เคฎाเคจเคคे เคนैं เค•ि เคญเค—เคตाเคจ เคเค• เคฎिเคฅเค• เคนै, เคœो เค•ेเคตเคฒ เคนเคฎाเคฐी เคฎเคจोเคฌเคฒ เค•ो เคฌเคข़ाเคจे เค•े เคฒिเค เคนी เคนै।     Often w...

Morning habits which can ruin your whole day

10 Bad Morning Habits Do you know the thing on which our whole day depends? If you think that this is morning, then you are absolutely right my friend. Our whole day depends on what we eat at breakfast, which time we wake up and what is the first thing we do when we woke up. 1. Snoozing your alarm:-   When you are going to sleep, that time you are fully determined that you woke up at 6:00 or 7:00am and you set up two or more alarm continuously with the break of 2 or 5 minutes. But in the morning, what happens? You start snoozing the alarm and doing this until you are late for your work. That time you have only one way to go to your work at the time is that you should skip your breakfast. Is it good? Absolutely not.  2.  Checking your message or E-mail just after you wake up 3. Drinking Coffee 4.  Not making your Bed 5. Eating Sugar for Breakfast:- 6. Leaving the Curtains closed:- 7. Not doing the Excercise 8. Doing ...