Consider the LARGESTMISSINGNUMBER problem below. Note that in this problem, ther
ID: 3844644 • Letter: C
Question
Explanation / Answer
#include <stdio.h>
void swap(int *xp, int *yp)
{
int temp = *xp;
*xp = *yp;
*yp = temp;
}
// A function to implement bubble sort
void bubbleSort(int arr[], int n)
{
int i, j;
for (i = 0; i < n-1; i++)
// Last i elements are already in place
for (j = 0; j < n-i-1; j++)
if (arr[j] > arr[j+1])
swap(&arr[j], &arr[j+1]);
}
/* Function to print an array */
void printArray(int arr[], int size)
{
int i;
for (i=0; i < size; i++)
printf("%d ", arr[i]);
printf(" ");
}
int main(void) {
int i, n, k;
scanf("%d %d", &n, &k);
int arr[n];
for(i=0; i<n; i++)
scanf("%d", &arr[i]);
bubbleSort(arr, n);
int temp=k+1;
for(i=n-1; i>=0; i--)
{
if(i!=n-1 && arr[i]==arr[i+1])
continue;
else
{
temp--;
if(arr[i]!=temp)
{
printf("%d ", temp);
break;
}
}
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.