最近初學Turbo C++
借了幾本書 大部分都看不懂 各位能不能推薦幾本入門好書
還要請教一下我第一次遇到的題目該怎麼用C語言寫出來:
Consider the following electric circuit with four resistances R1=8Ω,
R2=10Ω, R3=4Ω,R4=12Ω. If given a voltage source V=12volts,please write a C-program to find currents I1 through R1,I2 through R2,I3 through R3,I4 through R4 . And further,find V1,V2,V3,andV4.Print out your solution as follow:
-------------------------------------------------------------------------------
Resistor Current Voltage
( ohm ) ( amp ) ( volt )
-------------------------------------------------------------------------------
R1
R2
R3
R4
--------------------------------------------------------------------------------
(註:圖示為R1和R2並聯 R3和R4並聯後 再串聯起來 V為初始電壓)
2007-10-06 16:43:45 · 1 個解答 · 發問者 Anonymous in 電腦與網際網路 ➔ 程式設計
三條橫線為表格
要分別把電流和電壓表示出來
2007-10-08 18:18:48 · update #1
#include
#include
double p(double r1, double r2){
return r1*r2/(r1+r2);
}
double s(double r1, double r2){
return r1+r2;
}
int main(int argc, char* argv[]){
//=====START=====//
double r1=8,r2=10,r3=4,r4=12,rt;
double vr1,vr2,vr3,vr4,v=12;
double i,ir1,ir2,ir3,ir4;
rt=s(p(r1,r2),p(r3,r4));
vr1=v*p(r1,r2)/rt,vr2=vr1;
vr3=v*p(r3,r4)/rt,vr4=vr3;
i=v/rt;
ir1=vr1/r1,ir2=vr2/r2;
ir3=vr3/r3,ir4=vr4/r4;
printf("Resistor Current Voltage\n");
printf("%8.2lf %7.2lf %7.2lf\n",r1,ir1,vr1);
printf("%8.2lf %7.2lf %7.2lf\n",r2,ir2,vr2);
printf("%8.2lf %7.2lf %7.2lf\n",r3,ir3,vr3);
printf("%8.2lf %7.2lf %7.2lf\n",r4,ir4,vr4);
//=====END=====//
system("PAUSE");
return 0;
}
2007-10-06 17:23:44 · answer #1 · answered by Big_John-tw 7 · 0⤊ 0⤋