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
  • What is the output? #include <sys/types.h> #include <sys/wait.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> int main()...

    What is the output? #include <sys/types.h> #include <sys/wait.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> int main() { int x = 5; int y = 2; int z = 30; x = fork(); y = fork(); if (x != 0) printf("Type 1\n"); if (y != 0) printf("Type 2\n"); z = fork(); if (x > 0 || y > 0 || z > 0) printf("Type 3\n"); if (x == 0 && y == 0 && z != 0) printf("Type 4\n"); if (x...

  • ​what is the output? Consider the following program: #include <stdio.h> #include <stdlib.h> #define size 3 void...

    ​what is the output? Consider the following program: #include <stdio.h> #include <stdlib.h> #define size 3 void func(int **a) {int tmp; for (int i = 0; i < size; i++) {for (int j = i; j < size, j++) {tmp = *(*(a+i)+j); *(*(a+i)+j) = *(*(a+j)+i); *(*(a+j)+i) = tmp;}}} int main() {int **arr = malloc(sizeof(int*) * size); for(int i = 0; i < size; i++) {arr[i] = malloc(sizeof(int) * size); for (int j = 0; j < size, j++) arr[i][j] = 2*i...

  • please help, no explanation just need answer #include <stdio.h> #include <stdlib.h> int main(void) { int -x5);...

    please help, no explanation just need answer #include <stdio.h> #include <stdlib.h> int main(void) { int -x5); for (int = 0; i < 5; i++) { x[i] = malloc(sizeof (int) - 5); for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { x[i][j] = i j ; modify(x, 5, 5); return 0; Which of the implementations of method modify below set all elements of the matrix x to zero? 1. void...

  • computers. 1. How many times will this loop repeat? include <stdlib.h> #include <stdio.h> void main(void) int...

    computers. 1. How many times will this loop repeat? include <stdlib.h> #include <stdio.h> void main(void) int 10 for(= 0; i < 101) printf("d", 1); A. 10 times B. 1 time C. It will run forever D. 0 times 2. What will be the output of this program? #include <stdlib.h> #include <stdio.h> int main() int a = 100, b = 200, C = 300; if(!a >= 500) b = 300; C = 400; printf("%d, 8d, &d", a, b, c); return 0;...

  • #include <stdio.h> #include <stdlib.h> int aaa(); int main() { int ddd,eee = aaa (ddd,eee); printf("new num...

    #include <stdio.h> #include <stdlib.h> int aaa(); int main() { int ddd,eee = aaa (ddd,eee); printf("new num 1 = %d, new num2 = %d.\n", ddd,eee); return 0; } int aaa(int bbb,int ccc) {    bbb = 111;    ccc = 222;    printf("num 1 = %d, num 2 = %d.\n", bbb,ccc);    return bbb ,ccc;   } Output: num 1 = 111, num 2 = 222. new num 1 = 0, new num2 = 222. ************************************************************** I am learning function in C....

  • 1 4 7 10 2 5 8 11 3 6 9 12 I want to print...

    1 4 7 10 2 5 8 11 3 6 9 12 I want to print this matrix in c language. How did this formula come out? (3 * j + i + 1); #include <stdio.h> int main() { int y[3][4]; int i, j; for (i = 0; i < 3; i++) { for (j = 0; j < 4; j++) printf("%d ", 3 * j + i + 1); printf("\n"); } return 0; }

  • #include <stdio.h> #include <sys/time.h> #define DEBUG 1 //Constant is defined for true int main() { struct timeval start,end; //to store time of starting and ending of program //if state...

    #include <stdio.h> #include <sys/time.h> #define DEBUG 1 //Constant is defined for true int main() { struct timeval start,end; //to store time of starting and ending of program //if statement is added if(DEBUG){ gettimeofday(&start,0); } printf("Time in microsecond for every second: \n"); //output for(int i=0;i<100;i++) //outer loop to run 100 times { struct timeval loopstart,loopend; //to store time of starting and ending of loop //if statement added if(DEBUG){ gettimeofday(&loopstart,0); //measuring time at start of loop } for(int j=0;j<1000000;j++); //outer loop to...

  • what is output #include<stdio.h> pint main() { int i, j, total; for ( 2 { printf("\n");...

    what is output #include<stdio.h> pint main() { int i, j, total; for ( 2 { printf("\n"); for ( 2 { total = i + j; printf("%d", total); بہا } getchar(); return 0; } Find the for loop content | Output of progrm 5 15 1 11 21 31 41 51 61 2 12 22 32 25 3 13 23 33 43 53 63 4 14 24 34 44 54 64 35 45 6 16 26 36 46 56 66 7...

  • PLease explain output of these two programs: 1. #include <stdio.h> typedef struct { char *name; int...

    PLease explain output of these two programs: 1. #include <stdio.h> typedef struct { char *name; int x, y; int h, w; } box; typedef struct { unsigned int baud : 5; unsigned int div2 : 1; unsigned int use_external_clock : 1; } flags; int main(int argc, char** argv){ printf("The size of box is %d bytes\n", sizeof(box)); printf("The size of flags is %d bytes\n", sizeof(flags)); return 0; } 2. #include <stdio.h> #include <string.h> /* define simple structure */ struct { unsigned...

  • OPERATING SYSTWM Question 31 What is the output of this C program? #include #include void main()...

    OPERATING SYSTWM Question 31 What is the output of this C program? #include #include void main() int mptr, *cptr mptr = (int*)malloc(sizeof(int)); printf("%d", "mptr); cptr = (int)calloc(sizeof(int),1); printf("%d","cptr); garbage 0 000 O garbage segmentation fault Question 8 1 pts If this program "Hello" is run from the command line as "Hello 12 3" what is the output? (char '1'is ascii value 49. char '2' is ascii value 50 char'3' is ascii value 51): #include<stdio.h> int main (int argc, char*argv[]) int...

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