史萊姆論壇

史萊姆論壇 (http://forum.slime.com.tw/)
-   程式語言討論區 (http://forum.slime.com.tw/f76.html)
-   -   有關陣列的程式問題 (http://forum.slime.com.tw/thread220573.html)

rang0419 2007-11-19 04:34 PM

有關陣列的程式問題
 
看到陣列兩個字我投就要昏了:on_77:

根本不知道該如何下手..............


Write a menu-driven program that allows the user to fill an array of 50 integers with random numbers in the range of 0 to 1000. The program has the following functions:

(1) Fill the array with random numbers in the range of 0 to 1000. Each time this function is chosen the new random numbers is filled into the array.
(2) Print the array.
(3) Find the maximum and minimum value of the array.
(4) Calculate the mean deviation of the numbers in the array. The mean deviation is defined as Σ|x - x|/n where x = Σx/n.
Ex:
x1 = 124, x2 = 234, x3 = 562, x4 = 12 → x = (124 + 234 + 562 + 12)/4 = 233
mean deviation = (|124 - 233| + |234 - 233| + |562 - 233| + |12 - 233|)/4 = 165
(5) Count the value distributions.

A possible run may look like:
====================== Array Operation Menu ==================
1. Fill the array with random numbers in the range of 0 to 1000.
2. Print the array.
3. Find the maximum and minimum value of the array.
4. Calculate the mean deviation of the numbers in the array.
5. Count the value distributions for each consecutive 100 numbers.
6. Exit.
==========================================================
=> 1
50 random numbers in the range of 0 to 1000 has been filled into the array.
====================== Array Operation Menu ===================
1. Fill the array with random numbers in the range of 0 to 1000.
2. Print the array.
3. Find the maximum and minimum value of the array.
4. Calculate the mean deviation of the numbers in the array.
5. Count the value distributions for each consecutive 100 numbers.
6. Exit.
=========================================================
=> 2
The array is shown as follows:
578 984 630 927 146 917 369 922 598 550
101 51 481 230 901 82 669 759 395 639
42 930 34 576 374 448 359 659 692 705
521 978 303 938 877 18 24 530 487 302
416 186 496 71 667 386 542 877 338 615
====================== Array Operation Menu ===================
1. Fill the array with random numbers in the range of 0 to 1000.
2. Print the array.
3. Find the maximum and minimum value of the array.
4. Calculate the mean deviation of the numbers in the array.
5. Count the value distributions for each consecutive 100 numbers.
6. Exit.
=========================================================
=> 5
The value distributes are shown as follows:
Range Count
0 - 99 7
100 - 199 3
200 - 299 1
300 - 399 8
400 - 499 5
500 - 599 7
600 - 699 7
700 - 799 2
800 - 899 2
900 - 1000 8
====================== Array Operation Menu ==================
1. Fill the array with random numbers in the range of 0 to 1000.
2. Print the array.
3. Find the maximum and minimum value of the array.
4. Calculate the mean deviation of the numbers in the array.
5. Count the value distributions for each consecutive 100 numbers.
6. Exit.
==========================================================
=> 6
Bye!


有高手可以寫一下 借我參考嗎 感恩捏ˊˋ"

joebin 2007-11-19 07:33 PM

語法:

#include<iostream>
using namespace std;
int main(){
  int i,j,d[50],m=0,n=1000,x,a[10];
  srand(time(NULL));
  cout <<"The array is shown as follows:"<<endl;
  for(i=0;i<10;i++) a[i]=0;
  for(i=0;i<50;i++){
    if(i%10==0) cout <<endl;
    x=0;
    while(x==0){
      x=1;
      d[i]=rand()%1001;
      for(j=0;j<i;j++)
        if(d[i]==d[j]) x=0;
    }   
    if(n>d[i])n=d[i];
    if(m<d[i])m=d[i];
    if(d[i]<1000)a[d[i]/100]++;
    else a[9]++;
    cout <<d[i]<<" ";
  }
  cout <<endl<<endl<<"the maximum is : "<<m<<" ,and the minimum is : "<<n<<endl;
  x=m=0;
  for(i=0;i<50;i++)
    x+=d[i];
  x/=50;
  for(i=0;i<50;i++)
    m+=abs(d[i]-x);
  cout <<endl<<"the mean deviation is : "<<(m/50)<<endl<<endl;
  cout <<"The value distributes are shown as follows:"<<endl<<"Range Count"<<endl<<endl;
  for(i=0;i<10;i++){
    if(i!=0&&i!=9) cout<<i<<"00-"<<i<<"99 ";
    else{
      if(i==0) cout <<"0-99 ";
      else cout <<"900-1000 ";
    }
    cout <<a[i]<<endl;   
  }
  system("pause");
  return 0;
}

若有錯我只能說下次請給詳細的測試輸出資料好嗎??

看不懂你題目所規定的輸出,只好階段性輸出那5項要求:on_40:

rang0419 2007-11-19 07:44 PM

不好意思


因誤我收到的題目也就只有這樣了 囧


所以我也不知道 有沒有錯 今害.......

rang0419 2007-11-21 04:17 PM

對了 忘了講要用 C來寫捏 囧


你是不是用C++阿


所有時間均為台北時間。現在的時間是 02:30 PM

Powered by vBulletin® 版本 3.6.8
版權所有 ©2000 - 2025, Jelsoft Enterprises Ltd.

『服務條款』

* 有問題不知道該怎麼解決嗎?請聯絡本站的系統管理員 *


SEO by vBSEO 3.6.1