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.

what's wrong in this code

+1 vote
asked Aug 31, 2018 by Novice (240 points)
I wanted to find if the integers are unique or repeated and if repeated then how many times. I want to display the repeated integer only one time to show its frequency.

#include <stdio.h>

int main()

{

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

printf("Enter 4 integers :");

for(i=0; i<4;i++)

{

          scanf("%d",&arr[i]);

}

          for(i=0; i<4; i++)

          {

                 c=0;

                     for(j=0; j<4; j++)

                     {

                           if(arr[i]==arr[j])

                           {

                                 c++;

                             }

                    }

                     for(k=0; k<4; k++)

                    {

                              if(c>1)

                                  arr[k]=arr[i];

                  }

                              if(c>1)

                             {

                                     printf("\n%d was repeated %d times\n",arr[k],c);

                                      m=2;

                   }

        }

                  if(m==0)

                  {

                              printf(" All are Unique integers");

                  }

return 0;

}

1 Answer

+1 vote
answered Sep 3, 2018 by nk
#include <stdio.h>

int main ()
{
  int c = 0, arr[10], i, j, m = 0, k;

  printf ("Enter 4 integers :");

  for (i = 0; i < 4; i++)

    {

      scanf ("%d", &arr[i]);

    }

  for (i = 0; i < 4; i++)

    {

      c = 0;

      for (j = i+1; j < 4; j++)

    {

      if (arr[i] == arr[j])

          c=c+1;

    }

      if (c >= 1)

    {

      printf ("\n%d was repeated %d times\n", arr[i], c);

      m = 2;

    }

    }

  if (m == 0)

    {

      printf (" All are Unique integers");

    }

  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.
...