早上的考試

看板FJU-Stat94B作者 (未識綺羅香)時間17年前 (2007/01/09 13:55), 編輯推噓3(300)
留言3則, 3人參與, 最新討論串1/1
第一組 #include<iostream> using namespace std; int main() { double F[20]; F[0]=1;F[1]=1; for(int i=2;i<=20;i++) { F[i]=F[i-1]+F[i-2]; } for(int j=1;j<=20;j++) { cout<<"F"<<j<<"="<<F[j]<<endl; } cout.precision(5); cout<<F[20]/F[19]<<endl; cin.get(); return 0; } 第二組 #include<iostream> #include<time.h> using namespace std; double Uni_ran() { return (1.0+rand())/32769; } int main() { srand((unsigned)time(NULL)); double u1,u2; double c=0; double a=0,b=0; for(int i=1;i<=1000;i++) { u1=Uni_ran(); if(u1<0.5) {a++;} u2=Uni_ran(); if(u2<0.5) {b++;} if(u1<0.5&&u2<0.5) {c++;} } cout<<"P(u1<0.5且u2<0.5)="<<c/10.0<<"%"<<endl; cout<<"P( U1<0.5 )="<<a/10.0<<"%"<<endl; cout<<"P( U2<0.5 )="<<b/10.0<<"%"<<endl; cout<<"P( U1<0.5 )*P( U2<0.5)="<<(a*b)/10000.0<<"%"; cin.get(); } -- 霞乃雲魄魂蜂是花精神 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.136.162.56

01/09 14:03, , 1F
高手!!! 佩服佩服
01/09 14:03, 1F

01/09 15:36, , 2F
自M吧~~~
01/09 15:36, 2F

01/09 16:44, , 3F
高手~佩服佩服....
01/09 16:44, 3F
文章代碼(AID): #15eovbMf (FJU-Stat94B)