Free help with homework

Why join Brainly?

  • ask questions about your assignment
  • get answers with explanations
  • find similar questions

Write a c program to read n integers ranging from 1 to n that contain only one duplication and finding the repeated value and mixed in the array



#include<stdio.h>int main(){  int arr[50];  int *p;  int i,j,k,size,n;  printf("\nEnter size of the array: ");  scanf("%d",&n);  printf("\nEnter %d elements into the array: ",n);  for(i=0;i<n;i++)    scanf("%d",&arr[i]);  size=n;  p=arr;  for(i=0;i<size;i++){    for(j=0;j<size;j++){         if(i==j){             continue;         }         else if(*(p+i)==*(p+j)){             k=j;             size--;             while(k < size){                 *(p+k)=*(p+k+1);                 k++;              }              j=0;          }      }  }  printf("\nThe array after removing duplicates is: ");  for(i=0;i < size;i++){    printf(" %d",arr[i]);  }  return 0;}
1 4 1
some what inefficient program.. you do start comparing data from j = 0 onwards... you may do from j = i+1 onwards...

This Is a Certified Answer

Certified answers contain reliable, trustworthy information vouched for by a hand-picked team of experts. Brainly has millions of high quality answers, all of them carefully moderated by our most trusted community members, but certified answers are the finest of the finest.
#include <stdio.h>

  int A[100];  int i, j, n;
     printf"size: ");
     scanf("%d", &n);
     printf("values :  ");
      for (i=0; i<n;i++) scanf("%d", &A[i] );
     for (i = 0; i < n ; i++)  {
        for (j = i+1; j < n ;j++) {
           if (A[i] == A[j]) printf("%d th data item = %d is repeated\n",i,A[i]);
           for ( ; j<n-1; j++)  A[j] = A[j+1] ;  // remove the repeated one.
           n --;
   printf("the data items are : ");
   for (i=0; i<n; i++)  printf("%d  ", A[i]);

1 5 1
click on thanks button above pls;;;select best answer
The Brain
  • The Brain
  • Helper
Not sure about the answer?
Learn more with Brainly!
Having trouble with your homework?
Get free help!
  • 80% of questions are answered in under 10 minutes
  • Answers come with explanations, so that you can learn
  • Answer quality is ensured by our experts