0 like 0 dislike
11.8k 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
| 11.8k views

46 Answers

0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
* * ******* ** * * * ** x[] = {77,22,88,11,22};
** * ** ** **** * * size = 5;
    
** ** * ** ** ** * ** print the array */
***** * * * * * * ** i = 0; i < size; i++){
*** ****** * ** **** * * ** ********** * *** ** ** ", x[i]); * *** * * ******* * * * * ** *
*** *** ** *** * *
* ** ** * ** *** ** * **
** **** * * * * ** *
* * ** ** ** ** **** * * * * ** I need this to happen size-times */
** * * *** * *** ** **** j = 0; j < size; j++){
* *********** * * * * * ******* **** * *** from left to right */
* **** * * *** ** * * * *** * * i = 0; i < size-1; i++){
********* ** *** * * **** * * *** ****** *** * ** * **** * * *** i-th element with its neighbor to check if they are in order */
* *** * **** * **** * * **** **** *** ** * *** *** * ** *** * > x[i+1]){
* * *** * * * *** * * ** *** * * * ****** * ** * * * ** ** * ***** * * * * *** * ** exchange the values of x[i] and x[i+1] */
*** ** * ** * ** *** *** * ** ** * **** ** ** ** ** ** *** * * * * *** * ***** temporary; ** ** ***** *** * * * * * ** * ***
* ** * **** ***** * * * * ***** ** **** ** * * *** * * * ** * * *** ** ** * * ****** * = x[i];
* ******* ***** * * ** * *** ** * * ** * * * * ** **** ** *** *** **** *** * * * ******* = x[i+1];
** ** **** * * ** ** * *** * * ****** * * * ** ** * * ***** ** *** *** * * ** * = temporary;
* * * * * *** * * * ** * * * * ***** * *** * * ** **** ***** * **
* *** * * * **** *** ** * * * ** * * ** *
* * * * ****** *
** *** * **** * *
* *** * *** ** **** ** print the array */
* ***** ** * ** * * * * ** * * sorting: \n");
**** ** * ** ******** * * i = 0; i < size; i++){
* * * * ** * ** * *** * * *** ** ** * * * ", x[i]); **** ** ** *** * ** * * * * ** *
* ** *** ** * * ** *
* * * * * * ** * *** * * * * *
* * * **** **** *
**** * * *
* ** * * ** ** ** ** ** ** ** ** ****** * *** *
* * * * ** * * * * ** * ** * * * * * *  
* * *** * ** * * * * 0;
}
answered by (153 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
** * * ***** * ** * * * x[] = {77,22,88,11,22};
* ** ** * **** * **** * size = 5;
    
* * *** ** ****** * print the array */
***** ** * ****** ***** *** i = 0; i < size; i++){
* *** * * ** * ******* * * * ** * * * * ", x[i]); ** *** ** * * * * ** *
* * * * *** * **
** * ***** ******* ** * * ** *** *
** * ** * * *
**** * ** * * ** ** I need this to happen size-times */
* ** * * ** * j = 0; j < size; j++){
* * * *** ** ** * *** * *** ** * * ** ** from left to right */
** * * ** * * * * ***** * * ** *** * * i = 0; i < size-1; i++){
* ****** ** **** * ** * ** ***** * ** * * ** ** * ** ***** * ** ** i-th element with its neighbor to check if they are in order */
** * ** **** ** ** *** * **** ** * * ** * * ** ** **** ** * * * * **** > x[i+1]){
* ** * * * * * * * **** * * **** * ** ** * *** * ***** * ** * ** ** ** ** * ** * ** * * exchange the values of x[i] and x[i+1] */
** * *** *** ** * ** ** * * * ******* * ** * * **** * *** * * * * ******* *** temporary; ** **** * **** ** * * * * **
** * ** ** **** * * * *** * *** ** ** * * *** ***** ** * * **** * ** ***** *** * ** ** = x[i];
* ** *** * * * * ** ** * ******** ** **** ** ** ** *** *** **** * * * = x[i+1];
* * * *** * * * * * * * ******* ** * * * ***** * * **** *** * ***** **** * * * * = temporary;
* ** * ** * ** * * * * *** *** * * * * **** **** **
*** * **** * * * * *** * * ** **** ****
* * * *** ****
* * *** * *** ** *** * *
* *** * ** **** print the array */
**** *** * ** ** ** ** * **** sorting: \n");
* * ** *** ** * * ** i = 0; i < size; i++){
** * ** * * ** *** ** ** ** *** * * *** ", x[i]); ** * *** * * * *** ** * * **
* * ** * * * * ** * *
* **** *** *** * *** * *** * * ***** *
*** *** ** * *** * **
* ** *** * *** * *
***** * * * *** * * * * * ** * * ****
* ***** *** ** * ****** * ** * *  
* * ** ******** * ** ** * * 0;
}
answered by (153 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
** ****** * * * ** * x[] = {77,22,88,11,22};
* * * * ********** * ** * size = 5;
    
** * * **** * *** * ** ** print the array */
* *** *** *** **** * * * * i = 0; i < size; i++){
* ******* * ** ** *** * ** ***** **** ***** ** **** ** * ", x[i]); **** ** ***** * **** * **
* ** * * * ** * * *** **
* * ***** ***** ** * * * * ** * * **
** * * ** ** ** ***
*** * * ** ****** ** I need this to happen size-times */
* * **** ** * ** **** * ** j = 0; j < size; j++){
***** *** * * ** *** * * ** *** ** from left to right */
* * *** *** * * * * * ** ** **** *** * ** * i = 0; i < size-1; i++){
* * * * *** * * *** * * * *** ** ** ** * * ** * ******* *** ** * *** i-th element with its neighbor to check if they are in order */
* ** **** * *** ** * * * * ** * * * * *** *** *** * **** * *** * **** > x[i+1]){
* * ** ********** * *** * ** ***** * * *** * * ***** **** * * **** *** * * ****** ** ** exchange the values of x[i] and x[i+1] */
* ** ** *** * * * **** * * * ***** * ** *** * **** * * * ** ** ** * * ** **** temporary; ** * * ** *** *** * * * *** * * ***
* ** * ** *** ******** ** ** * * *** * **** * * ** ****** * ** * * *** * ** * **** *** * ** * = x[i];
** ******* * * *** * *** * * *** * ** ** ** **** **** * *** * ** ** * * ** * * * * * **** = x[i+1];
** * **** * * **** ** *** *** *** * **** ** ** * *** *** * ** * *** * ** ** ** * * ** = temporary;
********** **** * **** ********* *** ** * * **** **
* **** ** ** ** *** * ** * *** * * ** ***
*** * * *** * *** ** * *
* * * **** ** **
* ** ** *** ** *** **** print the array */
** * * * * ** * * **** ** sorting: \n");
** *** * * * *** ** ** i = 0; i < size; i++){
** * *** * ** *** ** * * * ****** * *** * ", x[i]); ** ** * * ** ** **** * * ***** ** *
* * *** * * ** *** ***
** ** * * * * * ** * * * **** ** *
** ** **** * ** ** * ** *
** ** ** ****** ** *
** * * ** * **** * **** ***** * **
* ** ** * * * *** ***** ****** * * ** *  
***** ** * ** * * * ** 0;
}
answered by (153 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
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
int i;

****** * * *** *** ** **** **** *
** * ** * ** ** * ** ** * * * ** ** * * **
* * * * *** * ** * ****
** * * * *** ** ** * * * **** *** ** *** * ******** * * ** ***** **** ** ***
* *** * **** * ** **** ** ******* **** * *
* * **** ** * * * * * **** * * **** * * ***** * * ** ********** * ****** *** ***** **
*** * ** ** ****** * *** * * *** * * ** * * * * * *** *********** ***
** * ****** * * ***** ** ** * ** *** *** * *** * * * * ** **
* *** ***** * * * *** ** * * * * **** * *
* ** ** ** * *
***** * *** ** ** ** **** ** ** *
**** **** * ** ** ** * * * * * * * ** * ** * * ** * ** * *
****  
* * * *** 0;
}
100/100 answered by (268 points)
0 0
prog.c: In function 'main':
prog.c:23:3: warning: implicit declaration of function 'system' [-Wimplicit-function-declaration]
   system("PAUSE");
   ^~~~~~
0 0
Case 0: Wrong output
Case 1: Correct output
Case 2: Wrong output
Case 3: Correct output
0 0
-----------Re-judge-----------
Case 0: Wrong output
Case 1: Correct output
Case 2: Wrong output
Case 3: Correct output
0 like 0 dislike
Hidden content!
#include ** * ** ** **
#include * * **

/* run this program using the console pauser or add your own getch, ** *** * ** * **** * or input loop */

int main(int argc, char *argv[]) {
** * *   int number[5];
    int size = 5, temporary;
    int i;
** **   **** *** *
** * * ** * * *** *** **** * *** * * *
* *   }
** * int a;
** * ** * * ** for(a = 0; a < size; a++){
* ***** * * ** ** int i;
*** *** ** * *** * * ** * * * * * ** ** = 0; i < size-1; i++){
* *** **** * * ** ** * **** ** * * **** ** * * * ** * * * ** **** ** * > * *
**** * ** ** *** ** *** ** ** * * * ** ** * * *** ** ** * * * ** * * * * * *** *** * **** ** ***** ** *
* **** ** * *** * ** * ** * * ** ** * * * ** **** * * ** * * ***** ** * * * = * *
** *** ** **** ** * ** ** * ******* ** **** ** ** ** *** * * ** * * ** * * * * **** = * *
* ** * ** * *** ** * ** ** * ***** * * ********* ** ** * *** * **** * ** * * = * *
**** * * **** * ***** ** ***** ** * * * * ** ***** * *
**** * *** ** * * ** * *** * *** ** * * * ****** **
***** *** * *
* * * ***** * **
** * * * * ** * * ***** *** ** sorting: * *** *
** **** ** **** * ** * = 0; i < size; i++){
****** * ** * ** ********* * * * * * **** ** * **** * * * ** * * ** * * * *** * * * ** ***** * ** *
** * * ** *** * * ** *
*** *   return 0;
}
100/100 answered by (252 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
#include * * * *** * * *

int main(){
** *** * int *** *
* **** * * int size = 5, * **
* **** **** *
* ** ** ** for(int **** ***
**** * ***** * * * * ** ** ** * * *
*** * * ** }
**  
* * * *** for(int * ** * ***
* * ** ***** * ** ** * * for(int ******* ** * *
* *** ** **** * * * * * * ** * ** * * * * ** *** * *
* *** * ** * * ** **** * ** ** * * *** temporary = ****
* *** * *** *** ** **** ** * * * * * * number[i] = * * * **
**** * ** * * * * *** * *** * ** *** *** ***** * = ** ***
*** ** ** ** * *** }
* *   }
}
* * * ** *
**** * ** for(int * *** * *
***   * *** *** ** ** ** *** **** *
* *** *** * * }
* * * * * **
* * * * * * return 0;
}
answered
reshown by
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:104.23.243.164
©2016-2026

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
| 7.3k 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
| 3.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
| 6.4k 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
| 3.3k views
12,783 questions
183,442 answers
172,219 comments
4,824 users