Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

how to find unique integers and repeated integers

0 votes
asked Aug 31, 2018 by Novice (240 points)
edited Aug 31, 2018 by Novice
I wanted to know how should I Find out the unique integers and repeated integers. I have somehow found the repeated integers with their frequency. But how should I do the rest?

#include <stdio.h>

int main()
{

int c=0,arr[10],i,j,m=0;

printf("Enter 10 integers :");

     for(i=0; i<10;i++)
    {
        scanf("%d",&arr[i]);
    }

    for(i=0; i<10; i++)
    {
       c=0;

      for(j=0; j<10; j++)
     {
        if(arr[i]==arr[j])
        {
              c++;
        }
      }

      if(c>1)
      {
          printf("\n%d was repeated %d times\n",arr[i],c);
       }
   }

return 0;

}

1 Answer

0 votes
answered Sep 1, 2018 by diekleinekuh
#include <stdio.h>

int main()
{

    int c=0,arr[10],i,j,m=0;

    printf("Enter 10 integers :\n");

    for(i=0; i<10;i++)
    {
        scanf("%d",&arr[i]);
    }

    for(i=0; i<10; i++)
    {
        c=1;
 

        //add the number of times the value of arr[i] exists after i
        for(j=i+1; j<10; j++)
        {
            if(arr[i]==arr[j])
            {
                c++;
            }
        }
        
        //if the value of arr[i] exists before i it has been treated already
        for (j=0; j<i; j++)
        {
            if(arr[i]==arr[j])
            {
                c=0;
            }
        }

        if(c>1)
        {
            printf("\n%d was repeated %d times\n",arr[i],c);
        }
        else if (c==1)
        {
            printf("\n%d was unique\n");
        }
    }

    return 0;
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...