0 like 0 dislike
8.7k views

Please write a program that receives 5 numbers in an array, then makes those numbers in ascending order by using bubble-sort.

**Use the template given below**

Code (Template)

#include <stdio.h>

int main(){
	int number[5]; // Do not change
	int size = 5, temporary; // Do not change
	
	for(int i=0;i<size;i++){ // Do not change
		scanf("%d",&number[i]); // Do not change
	} // Do not change

	// Your conditions start from here

	return 0;
}

 

Input 1

77 22 88 11 22

Output 1

11 22 22 77 88

 

Input 2

34 32 12 64 2

Output 2

2 12 32 34 64
[Exercise] Coding (C) - asked in Chapter 4: Arrays by (5.9k points)
ID: 37580 - Available when: Unlimited - Due to: Unlimited
| 8.7k views

46 Answers

0 like 0 dislike
Hidden content!
#include ** **
#include * ***** ** * **

int main(int argc, char *argv[])
{
** *   int number[5];
    int size = 5, temporary;
   
  **** for(int * ** ** * *
        ******* *** * ** ** ** **
    }
* ** * * **** *
** **** ** ** **** i = 0; i < size; i++){
****** **** * * ***** * * ***** * *** * *** * * ** i = 0; i < size-1; i++){
** ** **** * * * **** ** * * ** *** * ** **** ** * * * *** * ** ** > * * * * * * * * *** * *** * * *** **
* *** *** *** ** * * * * ****** * *** * * * * *** * ** * ** *** ** ***** * ** * * = number[i];
*** ** ** *** * * ** * **** * *** ** * * ** * * **** ** * * ** * * * ** * * ** * *** *** = * *** *
** * ** * * * * * *** ** ** * ** * *** * * * *** ** ***** * * ** * * = temporary;
* **** * * * * * ** * ***** * * * * ** * *** **** * ****
*** ** ** * ** ** ******** ** ** * *** *
* ****** ** ** *** ** *****
** *** ****** ***** *
**** ** * * * * * i = 0; i < size; i++){
* * ** *** ** * * ****** ** * **** * * * ** ** *** ** ***** ** * **** ****** **** *** ****
* ** * *** * ** * ***

* * ** ** * * * ** ***** ** * **  
** ** *** **** * * ** *** 0;
}
100/100 answered by (281 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 0
Case 0: Wrong output
Case 1: Correct output
Case 2: Wrong output
Case 3: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <stdlib.h>

int main(){
    int number[5];
    int size = 5, temporary,i,j;
   
    for(i=0;i<size;i++){
        ** * *** ** *** *** ** *** *
    }

** ** * ** * ** *** * ** * * **
* ** * *** * ****** *** ** *** * * ** ******* *** **** * ** * ************* * * *** **
** * **** **** *** *********** *** * * * *** ***** ** ** **** ** ** * * * * ****** ** **** ** * *** *** * * * *** * * *** ** * ***
** ** * ** ** *** * * ** * *** * *** * * * ** *** *** *** * * **** * ** = number[i];
* * * * ** *** * * *** ** * ** ** * * * *** * * ** * * ** ** = number[i+1];
* * **** * * * * * ****** * **** *** * * * * **** * * ** = temporary;
** *** * * * ** * * * * *** ** ** **** * * *
*** * ** ** ** *** * * * ** ** ** ** * ** * * *** * **
******* * ** * * * * * * ** * **** * * ** * ** * * * *
* ** * * * ***
*** * **** **** * ** ** ** *** * ** i=0;i<size;i++){
* ** * * * * ** ****** *** *** * * ** **** * ** * * ** * ** ", number[i]);
* ***** ******* * ** * * * * * * * * ** * * * * ** * * * ** **
**** **** ** **** *** *** * ** *** * ** ** ** *** * *** * **** * ** **
*** *** * * **** *** ** * * ** * * **** ***** ** ** ** *** * * * * **
*** * * * * * * ** ** * ***** * * ** * *
  
    return 0;
}
100/100 answered by (290 points)
edited by
0 0
prog.c: In function 'main':
prog.c:11:24: error: 'i' undeclared (first use in this function)
     for(int j=0;j<size;i++){
                        ^
prog.c:11:24: note: each undeclared identifier is reported only once for each function it appears in
prog.c:13:45: error: expected ')' before '{' token
                     if(number[i]>number[i+1]{
                                             ^
prog.c:18:13: error: expected expression before '}' token
             }
             ^
0 0
prog.c: In function 'main':
prog.c:12:24: error: 'i' undeclared (first use in this function)
     for(int j=0;j<size;i++){
                        ^
prog.c:12:24: note: each undeclared identifier is reported only once for each function it appears in
0 0
Case 0: Wrong output
Case 1: Correct output
Case 2: Wrong output
Case 3: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <stdlib.h>

int main(){
** * *** * * **** * number[5];
*** *** * ** *** size = 5, temporary;
    
** ***** * ** * * * * * i=0;i<size;i++){
* * * *** * ** * * *** ** * ******* **** * * * * * *** * **** * * ** * ** **** * * * ** * * * * * * * * *** *** * ** ** ** ** &number[i]);
**** ** *** * **** ** **
    
* ** * ** * ** * ** *** j=0;j<size;j++){
*** * * * ******* * * **** ** *** ** ** ** * ** ** ******** * ** **** i=0;i<size;i++){
* ** * ** ** * ***** ** ** *** ** * * * *** ** * * * * ** ** ** * **** * * * ** *** * ** ** ** *** * * * * **** * ***** * *
* ** * * * * * * * *** *** * **** ***** * ***** *** *** ** *** *** ** * ****** ** **** * ** * * ****** ** ** * * **** * ** ** * ** * = number[i];
* ** *** * * ** * ******* * ** ** ** * *** * ***** * * * * *** * ** ****** ** ****** * * ** * **** *** *** ** ** *** * * * ** ***** * * * ** = number[i+1];
* * * * ** ** * ************* * *** * ** ** * * ** **** * ** *** * *** * * ** * * ** * ** ****** ***** * * ** *** * = temporary;
* * * ** ** * * ** * ** * * ** **** * * *** *** * *** * * ** * ** * * ** ** * *** *** * * * * ***** **** *** *** *
** * * * *** **** ***** * ***** * *** ** ** *** ****** **** **
    }
* ** **** * * * *** **** ** *** ** ** * * * * *** **** ** **** ** * ** ***** ** ** ** * * ** ** *** ** *
***** * * *** * * * *** i=0;i<size;i++){
** * * *** * * * *** * ** * * ** **** * ***** ** ***** * ** *** * * * * * * ", number[i]);
    }
  
* * * * * * ***** **** * * **** * * * *****  
  return 0;
}
100/100 answered by (271 points)
0 0
Case 0: Wrong output
Case 1: Correct output
Case 2: Wrong output
Case 3: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>

int main(){
* ** ***** ** *** *** * ** number[5]; // Do not change
* ***** ***** ****** * * size = 5, temporary; // Do not change
** * *** *** * * ** ** i=0;i<size;i++){ // Do not change
*** ****** ** * ** *** * * * ** *** *** * ** * ***** * * ** * * ** * // Do not change
* * *** ** ** **** ** *** // Do not change
int i;

* * ** ***** ** ******* * * ** ** * **** ***
*** ** * ** * ** * ** *** i=0;i<5-size-1;++i)
***** *** ***** ** *
*** *** * *** *** * * *** *** * ** * **** ***** ** *** * ***   
*** * * **** ********* ** ** *** ** * ** * * * * *
* * **** ***** ** *** ***** *** * ** * * *** **** ***** * * ** ***** * *
* **** * * ****** ** **** ** *** ********** * * *** *** * **** *** *
* ** * ** *** * * * *** ***** * ** ** * * *** * * * * * **** ****** *** *
* ** * *** **** ** * ** * ** *** * *
* ** *** *
* * *** *** * * ** ** *** * *
* * ** * ** * * * * * ** **** * ** ******* *** ** ** * ",number[i]);
* * ** * * *** * * ** *
  return 0;
}
100/100 answered by (192 points)
0 0
Case 0: Wrong output
Case 1: Correct output
Case 2: Wrong output
Case 3: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>

int main(){
*** **** * * ** * number[5]; // Do not change
* *** * **** * ** * * * size = 5, temporary; // Do not change
* *** *** ***** ** *** * i=0;i<size;i++){ // Do not change
* * * *** * * * * * * ******* * * ** ** ******* * * * ** * *** // Do not change
** ** *** * * **** ** // Do not change
int i;

* * ** * * ** * * *** ** ***** * *** * *
*** **** * ** * * * **** i=0;i<5-size-1;++i)
* * ** *** **** * ***
** * *** * *** * ** ** * * * * * * * ** * ** * ***** **** *   
* * * * *** *** *** * ** ** *
**** ** * * * * * *** ****** ** * * **** * * *** * ** * * * **
** ** ** *** ***** ** * * *** ** ** * * * ********* ** * ** * *** * * **
* **** * * * * **** * **** *** * * * * *** ** ** * ** * *** * ******* * ***
**** * ** * ***** * ** * *** * ** * **
* ** *** **** * **
** ***** **** * * * **** * * * *
** ****** * ******* * *** * * * ******** * ***** * * ",number[i]);
********* * * ** ** **** * **
  return 0;
}
100/100 answered by (254 points)
0 0
Case 0: Wrong output
Case 1: Correct output
Case 2: Wrong output
Case 3: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>

int main(){
    int number[5]; // Do not change
    int size = 5, temporary; // Do not change
   
    for(int i=0;i<size;i++){ // Do not change
        * *** * * * * * * ** * // Do not change
    } // Do not change

    // Your conditions start from here
    for(int i=0;i<size;i++){
* * ***** * ** ** *** **** ** ** ** * * * *** ** ** * * ** j=0;j<size;j++){
** * ** *** *** * * * * ** * * *** * * ****** ** **** * * ** * * * ***** *** * ** * * * * *** ***** ***** *
** ** *** * * * ** * * ** *** ** * *** **** * * * * *** * * * ****** * * * *** * * ** * *** * * * ** ***** * *** * * *** * ** ** ** * *** * ** **** * * * * * * * ** * **** * * * ** * * * **** ** * ** * ** * * * * *** * ** ** = number[i];
** ** * ***** * * *** * * ***** * * * *** * ** * * * ***** * *** * **** ** * * * *** * * * **** * ** * * ***** *** *** * * ** * * **** ** *** ****** **** ** ** * * * * ** * * * * **** *** * ** *** ** ****** * * *** ** * * ********* * * = number[i+1];
* *** ****** * * * * * * * * ** ** * * ** * ** ** *** * * ** ****** *** **** * * * ** *** **** * ** **** * * * * * **** ** * * * * *** ** ** ** ** ** *** * **** * * **** * * ** *** ** * ** * * ** ** * * *** * * * * ** * ****** *** * = temp;
***** ** * ****** ** * * * * ** ** ** * ** * ** * * ** * * **** ***** * ** * * * * * * * * * * * **** * * *** ** * * * ** ** * * * **** ***** * ******** ****** * ***** ** * * ***** * *** * * * * ****** ** ** * * *** *** *** ** ** ***** ****
* * ** ** * * * ** ** ** * ** * *** * * * * * ** * * * * ** * * *** * *** * ** ** * ** *
** ** ** **** ** * * * * *** * * ** * * *** * **** * * * * * * **
for(int i=0;i<size;i++){
*** * * * **** * **** * ******* ** * * * * ** **** ** * ",number[i]);
* *** ** ** ** ** * * * *** ******* * *** *
    return 0;
}
80/100 answered by (227 points)
0 0
prog.c: In function 'main':
prog.c:15:47: error: 'temp' undeclared (first use in this function)
                                               temp = number[i];
                                               ^~~~
prog.c:15:47: note: each undeclared identifier is reported only once for each function it appears in
0 like 0 dislike
Hidden content!
#include <stdio.h>

int main(){
* * * ****** ** * ***** number[5]; // Do not change
** ************ ** * ** size = 5, temporary; // Do not change
* *** * ** ** * i=0;i<size;i++){ // Do not change
* ** ** * * * * * ** * * ** * *** *** * * * * ** * * * ** // Do not change
** * *** *** * * ****** * // Do not change
int i;

** * *** * ** *** *** ** ** * ** *
** * ** **** * * *** * * ** * i=0;i<5-size-1;++i)
* ** ** ** *
** *** ** ** ** ** * * * ** **** ** * ** * ****** * ****** *   
**** ***** ** *** * *** * ** * * * ** ** *
*** * ** * * ** ** ****** * *** * ** ** * * ** **** * ** * *** ** *** * * ** * *
* ** *** * * * * * * * * * ** * * ** ** * ** * ** * *** * * *** * *
** *** *** * * ** ** * * * * * * ** * * *** * *** **** * **** * *
*** * *** * ***** * * ** **** *** * *
* * * * * *
* * *** * ** ** ****** ***** ****** * ***
** ** ***** * * * * * * ** * * ** ** * * * * ** ** * ",number[i]);
* ** * * ** * *
  return 0;
}
100/100 answered
0 0
Case 0: Wrong output
Case 1: Correct output
Case 2: Wrong output
Case 3: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>

int main(){
*** *** * ** * *** ** * * number[5]; // Do not change
** * * * * * * * size = 5, temporary; // Do not change
* * ** ** * **** * * i=0;i<size;i++){ // Do not change
* * ** * *** ***** ** *** ********** * ** * ** * ** * **** * * * * * // Do not change
*** * * ** * * * * * * ***** // Do not change
int i;

* * **** * * **** * *** **
* ** **** ** i=0;i<5-size-1;++i)
** ** ** * *** ****
***** **** **** ** *** * **** ** * ** * * * ** * * ****** *** * **** *   
**** * ** ****** ** * * * * * * *** ****** **
*** * * ******** * **** *** *** ***** * * ** ** * * ** ** ** * **
** * **** *** ** * *** * * * * * * * *** ** ** ** ***** ** ** * *
** * ** * * * * * * * ** * * * ***** *** * * *
*** ***** * * ** * * * ** * * * * ** *****
* * * * **** *******
* **** * *** ** *** * * ** *** **
* * ** *** **** * ** ** * ** * * ** ** * * * **** **** ** ",number[i]);
** * ****** * *** * * *
  return 0;
}
100/100 answered by (183 points)
0 0
Case 0: Wrong output
Case 1: Correct output
Case 2: Wrong output
Case 3: Correct output
0 like 0 dislike
Hidden content!
for(int ** * **
** * *** ** * ** * * for(int * * * * * * *
* * * * * ** * ** * *** ** * * ****** **
** * *** ** * ** ** *** * *   * ** * *** ***
* ** *     * **     * ** **   * **** *
* ****   ** * ** *** ** * ** * * ***** ** * **
*** * * ** * * * * * **** * ** ** * * }
* * **** ** * * }
** * ** * }
** ** * **
*** * for(int ** **
*** * * ** * * ** * * * ****** ** * * ** * *
** ** *** *** * }
50/100 answered by (244 points)
0 0
prog.c:1:1: error: expected identifier or '(' before 'for'
 for(int i=0;i<size;i++){
 ^~~
prog.c:1:14: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
 for(int i=0;i<size;i++){
              ^
prog.c:1:21: error: expected '=', ',', ';', 'asm' or '__attribute__' before '++' token
 for(int i=0;i<size;i++){
                     ^~
prog.c:11:2: error: expected identifier or '(' before 'for'
  for(int i=size-1;i>=0;i--){
  ^~~
prog.c:11:20: error: expected '=', ',', ';', 'asm' or '__attribute__' before '>=' token
  for(int i=size-1;i>=0;i--){
                    ^~
prog.c:11:25: error: expected '=', ',', ';', 'asm' or '__attribute__' before '--' token
  for(int i=size-1;i>=0;i--){
                         ^~
0 0
It's missing a header which is #include
0 like 0 dislike
Hidden content!
#include * * ** ** * *

int main(){
* * * *** * * * int number[5]; // Do not change
* ***   int size = 5, temporary; // Do not change
* ** *** ****
    for(int * * ** * * // Do not change
*** **     * * * **** ** * * ** ** // Do not change
* ** ** } // Do not change

**   // Your conditions start from here

* *** * j = 0; j < size; j++){
* * **** * * *** ** * ** ** ** * ** *** i = 0; i < size-1; i++){
* * * **** *** * * ** * * * * * *** *** * * **** * *** ** **** > **** *
**** * *** *** * *** ********* * * *** *** **** * * ****** ** ** ** * * ***** **** *** ** temporary; * * * ** ** * ** *** * * *
* * * * *** * * * * * * * * * ** * * * * *** ******* * * ****** ***** *** ** * **** * * = * *** *
** *** ***** ***** ** **** **** * * *** *** *** ***** ** ** * **** * * * * ** ** ** ** = * *
* **** ** * * ** **** *** ** * * * * ****** * * *** ** *** ***** ** ** ** *** = temporary;
***** ** * * ** **** ** ***** * *** * * *** ** * *** * ** **** * * *
** ** ****** * * * * * * * *** *****
*** * * * *** ******
* * **** * **** ** *
* ***** * * * * ** ** *** i = 0; i < size; i++){
*** * ** **** * *** * * * ***** * ******** * **** * ** * ** ******* ** *** * **** * ***** * ** ** ** ** ** * ** **
** * * *** ** *
*** * * *** return 0;
}
100/100 answered by (221 points)
0 0
Case 0: Wrong output
Case 1: Correct output
Case 2: Wrong output
Case 3: Correct output
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.70.194.139
©2016-2025

Related questions

0 like 0 dislike
0 answers
[Resource] asked Dec 15, 2017 in Chapter 4: Arrays by nat236919 (5.9k points)
ID: 37571 - Available when: Unlimited - Due to: Unlimited
| 6 views
0 like 0 dislike
18 answers
[Exercise] Coding (C) - asked Jan 5, 2018 in Chapter 4: Arrays by nat236919 (5.9k points)
ID: 41054 - Available when: Unlimited - Due to: Unlimited
| 5.5k views
0 like 0 dislike
20 answers
[Exercise] Fill in the blank - asked Dec 15, 2017 in Chapter 4: Arrays by nat236919 (5.9k points)
ID: 37578 - Available when: Unlimited - Due to: Unlimited
| 2.7k views
0 like 0 dislike
17 answers
[Exercise] Coding (C) - asked Dec 7, 2017 in Chapter 4: Arrays by nat236919 (5.9k points)
ID: 35804 - Available when: Unlimited - Due to: Unlimited
| 4.7k views
0 like 0 dislike
18 answers
[Exercise] Fill in the blank - asked Dec 7, 2017 in Chapter 4: Arrays by nat236919 (5.9k points)
ID: 35798 - Available when: Unlimited - Due to: Unlimited
| 2.4k views
12,783 questions
183,442 answers
172,219 comments
4,824 users