Question

Debug to print output "2 3 5 6 8 11": #include <stdio.h> #include <stdlib.h> int main()...

Debug to print output "2 3 5 6 8 11":

#include <stdio.h>
#include <stdlib.h>

int main()
{
   int i, j, n;
int A[] = {2, 3, 5, 5, 5, 6, 8, 11, 11, 11};
   n = sizeof(A) / sizeof(int);

   for (i = 0; i < n - 1; i++){
       if (A[i] != A[i + 1]) {
           for (j = 1; j < n - 1; j++) {
               A[j] = A[i];
           }
               j++;
           n--;
           i--;
       }
   }
   for (i =0; i < n; i++) {
       printf("%d\n", A[i]);

   }
   return 0;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

ANSWER: Here I corrected the code and remove the duplicate items from the array and print it Please like it.

CODE:

#include <stdio.h>
#include <stdlib.h>

int main()
{
int i, j,k, n;
int A[] = {2, 3, 5, 5, 5, 6, 8, 11, 11, 11};
n = sizeof(A) / sizeof(int);

for (i = 0; i < n; i++){

for (j = i+1; j < n; j++) {
if(A[i]==A[j])
{
for(k=j;k<n;k++){
A[k]=A[k+1];
}
n--;
j--;
}
}

}

for (i =0; i < n; i++) {
printf("%d ", A[i]);

}
return 0;
}

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
Debug to print output "2 3 5 6 8 11": #include <stdio.h> #include <stdlib.h> int main()...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT