0 like 0 dislike
4.3k views
請設計一程式,從使用者輸入的數中找出中位數輸出。使用者輸入的第一個數字N代表接下來會有多少個數字會被輸入,程式會從接下來的N個數中找出中位數輸出。

sample input:

4

1 2 3 4

sample output

2.5
[Exercise] Coding (C) - asked in 2016-1 程式設計(一)AD by (18k points)
ID: 15439 - Available when: 2016-10-27 18:30:00 - Due to: 2016-10-27 21:00:00

reshown by | 4.3k views

73 Answers

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

#include<stdlib.h>



int main()

{
* *** * ** * * *** i,k,l,j;
** * *** * * *** ** *** * a;
* * ******* * * ** * * ******* * * ** ** ** *

    
** *** ** ** * ** *** n[i];
***** *** * ** **** ****
* *** ***** * ** * * ** = 0;k < i;k++)
*** * * ** * * ** ** * ** * ****** ** * * ** n[k]);
* *** ** * * * * ** * ** *** *** ** * **
* * *** ******* * *** ** * * * * = 0;l <= i;l++)
* *** * ** * * ** * ** *** = l + 1;j <= i;j++)     
***** ** * **** *** ** * **** * * < n[i])
* ** * * * * * * * * * * ** = n[j];
* * * ** ** ** ** * * * ** * *** * * * = n[i];
*** **** * *** ** * ** *** * * * ** ** * * *** * * * = m;}; ** *** *** ****** *** *** ** *** ** * * **** *

   
* *** * ** * ** * % 2 == 0) * ** * * *** ** ***** * * * *** **** * ***** ** ****** * * * * * * ** *** ***** *** *** ** * ** * ********* *
* * ** * * * * * * * =(n[i / 2] + n[i / 2 - 1]) / 2;
** *** ** ***** * *** ** * ** * * * ** ** * ***
** * * * *** ** * *
* * * ********** % 2 != 0)
* * ** ** ** *** ** * ** = n[i / 2];
* ** * * * * ** ***** ** * };
* * * * * * * * * * * **
* * *** * * * * *** * * * * * * * ** * ***
* *** * ** ** * ** 0;

}
answered by (-264 points)
0 like 0 dislike
Hidden content!
#include<stdio.h>

#include<stdlib.h>



int main()

{
* ** ** * * * * * * i,k,l,j,m;
**** *** ** ** * *** * * * a,b;
* ** ******** * ** ** * * *** ** ***
* ** * * * * *****
** **** * *** *** * n[i];
** ** * * * ** ** * **
** ** * *** * ** * = 0;k < i;k++)
**** ** ******* * * *** *** * *** ** ** * n[k]);
* * * *** ** * *** ** ****** * * ** * ** ***
* ** ** * * * ** ** **** * ** * = 0;l <= i;l++)
* * * * *** * *** ** ** ** ***** = l + 1;j <= i;j++)     
* * * * *** ** ** *** * * ** ***** < n[i])
* * ****** **** * * ***** ** **** * = n[j];
** ** * * * ** * ** *** * * * ** * * = n[i];
* ** * * * ** * * * * ***** * ** = m;}; * * * * * **** * * ** *** *** * *** * ** *

   
**** ** *** * ***** ** % 2 == 0) *** * * * * * ** * * * *** ** * ** * *** * ** * ** * ***** ** * * *** * * * ***** * * **
* ** * **** * ****** =(n[i / 2] + n[i / 2 - 1]) / 2;
*** * * * ******* ** * *** ***
* ** * *** *
*** * * *** * * * ** % 2 != 0)
***** ** ** * ** *** = n[i / 2];
* *** * * * * *** ** **** ** * ** **** };
* *** ****** ** * * ****** * **** *
* ******* ** ** ** ** * *** * * * **** *
* ******* ** ***** * * * * 0;

}
answered by (-264 points)
0 like 0 dislike
Hidden content!
#include <stdio.h>

#include <stdlib.h>

#include <math.h>

int main()

{
* * * ** ** **** ***** *** in;
* ** ***** ** *** *** **** ** ** ** *** &in);
** *** * *** **** *** * mid=0;
* **** * * * * * * * i,j,tmp;
** * ** * *** num[in];
** ****** ***** ** i<in; i++)

    {
** ** ** * ** * * **** ** * *** ***** * * ***** * * &num[i]);

    }
* * * ** ** * ** * ** *** i<in;i++)

    {
* ****** * * * * **** * * **** * ** * * *** * * * j<=4; j++)
* * ****** ** *** * * ** * * ** * * *
*** *** * * ****** *** * * ** ** * ** ** *** * ** *** ******* ** ** *
** * * * ** ** *** * *** ** * ** * *** *** * * * ** * ** * * ***** ***
** ******* ** ** ***** * **** ** *** ** **** * * * * * ** * * ** *** *** ** * **
*** ***** ** ****** *** **** **** * * *** * * * ** * * ** * * ***** * **** *** ** ** *** * * ** *** * * *
* * * ****** * ** * *** ** **** * * ** * ** * * ** *** * * * ** * * * ****** **
*** * ******* * ***** ****** * ** ** ** ** ** *** ** * * *** *
** * ** ** ** * * * * *** ** ** * *
** * ** ***** ** * **
* ** ** * *** ** * *** * * % 2 ==0)

    {
** * * * * * * * * *** = (num[(i/2)+1] + num[(i/2)])*0.5;
** **** *** * ** * * * * ** *

    }
*** * ** ** * *** *** if(in % 2 != 0)
*** * ** * *** *** *
*** * * * ** * * ** * ** * ***** ** * * = num[(i)/2+1];
* * * ***** * * *** *** **** ***** * ** * *** ** *
** *** * * * * *
** ** *** * ** **** *** * * * 0;



}
answered by (-202 points)
0 like 0 dislike
Hidden content!
********* **** *****



int main()

{
* * ** **** * * * A,B,[C];
* ** ****** ** D;
** **** * ***** ** * ** ** *
* * *** * * * * ***** * **
*** ** ** * ** ** * * ** ******

  }
**** * *** ** * *
*** **** ** ** * * ** ** ***

}
answered by (-102 points)
0 like 0 dislike
Hidden content!
#include <stdio.h>

#include <stdlib.h>

#include <math.h>

int main()

{
* * ** * ** * * ** * in;
* * * ** ****** * * * * * ** ** ** &in);
*** * ** ** *** ** * * * * mid=0;
**** ***** * **** * *** * i,j,tmp;
**** ** *** * *** * num[in];
** ** * * *** ** *** *** i<in; i++)

    {
* ** ** *** ** ***** * * * * *** * * * * **** &num[i]);

    }
** *** ** ** * * * ** i<in;i++)

    {
**** *** * * ** ** *** ** *** ***** *** * ** * j<=4; j++)
* **** * * *** * * * ** **** * ** *
* ** ** * * ***** * * * * ** *** * * ** * ** * * * * *** * * ** ** * * * ******* ** *
* *** ** * ** * *** ** * ** * * ***** *** * ** ****
** *** * **** * * * * ** *** * * ** * *** **** * * ** * ** ** ** **** ***** * * ** ** * * ** * *
* * * * * * ** ** * * * ** **** *** ** ** ** ***** * *** **** ****** * *** * ******* **
***** ** * ** ** * * * **** * *** * ** * *** * *** * *** ** ** * *** * * ****** * * * * * **
* * * * *** * * * * *** ***** * ** **** ** *** * * * *
* * **** * * *** * * * *** ** * * ** ****
* *** * * ** * * * * *
***** * * *** **** *** * % 2 ==0)

    {
* * ** ** * * *** ** * *** * = (num[(i/2)+1] + num[(i/2)])*0.5;
* ** * *** ** * ****** *** ** * * ** *

    }
** ***** * ** * *** *** ** if(in % 2 != 0)
*** ** * * ** * *
***** * * * * ***** * * * * * * ** * * * * = num[(i)/2+1];
** * * * **** ** ** ***** * *** ** *** ** *** * ** ** * ** **
*** * * ** ** ***
***** ** * ** * * ** * * 0;



}
answered by (-202 points)
0 like 0 dislike
Hidden content!
#include <stdio.h>

#include * * **** * **

#include <math.h>

int main()

{
* * * ** * * **** ** ** * * in;
******** * * * ******* * * **** ** **** ** &in);
**** * ******* ** * * mid=0;
* **** ** * *** * ***** * i,j;
*** **** * * * num[in];
* * * * * * ** ** ** * i<in; i++)
*** ***** ******* * *
* *** * * * * *** * ** * ** *** * * * * *** * * * * * *** &num[i]);
* *** ***** * *** * **
** *** * ** ****** ** ***** ** % 2 ==0)
* ** ** * * * **
* **** * * ** *** * * = (num[in/2-1] + num[(in/2)])*0.5;
* ** * * * * * **** * ** * * ******* * ** * **
* ** ** **** ** ** ** *
** ** **** ** *** * ** ** if(in % 2 != 0)
**** * * *** * * ** ***
* * ** *** * **** * *** *** ***** **** **** * = num[(in)/2];
*** * ***** * ** **** ** * **** ** ** ** *** * * * *** * *******
***** ** ** ** * * *
* *** * ***** ***** * 0;



}
answered by (-202 points)
0 like 0 dislike
Hidden content!
#include <stdio.h>

#include ** ** * ** ***

#include <math.h>

int main()

{
* * *** * ** *** * ***** ** in;
* * * * * *** * **** ** * *** ** *** &in);
* * ** * ** * * ** * * * mid=0;
*** ** ** * ** * * *** * ** i,j;
*** *** ** *** ** * num[in];
* * ** * ****** * *** * * i<in; i++)
***** * * * * *** *
* *** * * ** **** * * * ** * ** ** ** * ** * *** * **** ** &num[i]);
** ** ** * * * ** *
*** * *** * * * **** *** % 2 ==0)
* ****** **** ** ****
* *** ** ***** **** ** * * * = (num[in/2-1] + num[(in/2)])* 0.5;
*** ** ***** **** * ** ** * * *** * * ** *** * *
* * * ** ** * ** *
** ** ***** **** ** if(in % 2 !=0)
* * * * * * *
** * * * ** ** * * * ** * ** * ** ** = num[(in)/2];
* * * * **** ** ** ***** ***** **** * ** * * ****** * *** * * ** ****
*** ** ****** * * **
* ** ****** *** * * ****** 0;



}
answered by (-202 points)
0 like 0 dislike
Hidden content!
#include <stdio.h>

#include ** * *****

#include <math.h>

int main()

{
* ** **** ** * in;
* * * * *** * * * *** * ** * * *** &in);
* * * **** * ** ** *** *** mid=0;
* ** *** *** ** ** * * * * i,j;
** ** ** ** * ** * *** num[in];
** * ***** * * *** i<in; i++)
* ** ** ** * * * *
** ** * * * ***** * * *** * ** **** ** * **** ** ** * * ** ** &num[i]);
******** * * * ***** **
* * ** * ***** * ** ** % 2 ==0)
***** *** * ********** *
*** *** ** ** ** **** * * *** = (num[in/2-1] + num[(in/2)])* 0.5;
* * ** ***** ** * * * * * * * ***
* * ** **** ** *** *
* * * *** **** ** **** if(in % 2 !=0)
** ** *** ** * * ** *
* * * ***** ** ** * *** * **** * ** ** = num[(in)/2];
**** * ** *** **** * * ***** * * *** ** * ** * ** ** * ** ** * * **
***** ** * ** *** * *
* * **** *** * * * **** ** * * 0;



}
answered by (-202 points)
0 like 0 dislike
Hidden content!
#include <stdio.h>

#include ** **** * ** *

#include <math.h>

int main()

{
*** *** **** * ****** *** in;
** * * * * ** * * ****** *** * * * * &in);
** * * ** * ** * * ***** mid=0;
*** * * * **** i,j;
** ** *** ** ****** * * num[in];
*** * *** * ** * * *** * i<in; i++)
* ** * ** ** * * * *
* *** * * * ** *** ***** *** * *** ** * **** ** ** *** &num[i]);
* ** *** ** *** * * *** * *
*** ** * * ** ** *** **** % 2 ==0)
* * * * ** * * ****** * ** *
* *** * * * **** * = (num[in/2-1] + num[(in/2)])* 0.5;
*** *** ***** * * * *** ** * ** ** * ** *
* * ** ** * * *** **
*** * ** * * * ******* if(in % 2 !=0)
* * **** * ***** * *
* ****** ****** *** * * * * * * ** ** * * ** * *** = num[(in)/2];
* * *** * * *** ** * * * * *** * *** * ** ** *** * * *
* **** * * * ***** * ***
** * ** * ***** **** * *** 0;



}
answered by (-202 points)
0 like 0 dislike
Hidden content!
#include <stdio.h>

#include * * **

#include <math.h>

int main()

{
* * * * *** ** * * * in;
* ** ** * ** * *** * ** ** *** * * &in);
* **** * * * * * **** mid=0;
* ** *** ** * *** *** * ** i,j;
** *** ****** * * * * num[in];
* *** * ** * * * * * ** i<in; i++)
** * * ** **** * * *
* * * * * * * * * * * * ***** ***** **** * * *** * ** * * &num[i]);
** * * ** * ** * *
** * ** ** ** *** *** * % 2 ==0)
* **** * **** * *
** **** * ** ** * * * * = (num[in/2-1] + num[(in/2)])* 0.5;
* * * * * * **** ** * *** * *** * ** ** * * * * * **
* * ** * * * ***
* * ****** ** ** *** if(in % 2 !=0)
* *** * * * * ***** *** *
* *** *** ** * ** *** * * *** ** * * ** * ** * * = num[(in+1)/2-1];
* * * * * ** **** * **** * ** * ** ** ** ** * * * * * *** *
* * * ** *****
* * *** * * * ** *** **** 0;



}
answered by (-202 points)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.70.127.98
©2016-2025

Related questions

0 like 0 dislike
5 answers
[Exercise] Coding (C) - asked Oct 27, 2016 in 2016-1 程式設計(一)AD by Shun-Po (18k points)
ID: 15448 - Available when: 2016-10-27 18:30:00 - Due to: 2016-10-27 21:00:00
| 661 views
0 like 0 dislike
33 answers
[Exercise] Coding (C) - asked Oct 27, 2016 in 2016-1 程式設計(一)AD by Shun-Po (18k points)
ID: 15445 - Available when: 2016-10-27 18:30:00 - Due to: 2016-10-27 21:00:00
| 2.4k views
0 like 0 dislike
11 answers
[Exercise] Coding (C) - asked Oct 27, 2016 in 2016-1 程式設計(一)AD by Shun-Po (18k points)
ID: 15441 - Available when: 2016-10-27 18:30:00 - Due to: 2016-10-27 21:00:00
| 1.2k views
0 like 0 dislike
41 answers
[Exercise] Coding (C) - asked Oct 27, 2016 in 2016-1 程式設計(一)AD by Shun-Po (18k points)
ID: 15427 - Available when: 2016-10-27 18:30:00 - Due to: 2016-10-27 21:00:00
| 2.9k views
0 like 0 dislike
28 answers
[Exercise] Coding (C) - asked Oct 27, 2016 in 2016-1 程式設計(一)AD by Shun-Po (18k points)
ID: 15421 - Available when: 2016-10-27 18:30:00 - Due to: 2016-10-27 21:00:00
| 2.3k views
12,783 questions
183,442 answers
172,219 comments
4,824 users