fl1pfl0p 0 Report post Posted November 3, 2007 (edited) as'kum,nak mintak bantuan dari sape2 yg power c.. camni aku buat program untuk mengira nilai T jika diberi nilai l .Formulanya mcm ni T = 2 * PI * ( l / g)^0.5 di mana PI = 3.14159 dan g = 9.81. T adalah period dan l adalah length.ni formula ayunan bandul.ni source code yg aku buat:#include <stdio.h> #include <conio.h> #include <math.h> #define PI 3.1415926 #define g 9.81 int main() { int i = 0; double T[4],l[4]; do { printf("Enter the value of period %d to find the length: ", i+1); scanf("%lf", &T[i]); fflush(stdin); l[i] = g*pow((T[i]/(2*PI)),2); i++; } while(i<5); for(i=0;i<5;i++) { printf("The length for period %d is : %lf\n",i+1, l[i]); } i=0; do { printf("Enter the value of length %d to find the period: ", i+1); scanf("%lf", &l[i]); fflush(stdin); T[i] = 2*PI*pow((l[i]/g), 0.5); i++; } while(i<5); for(i=0;i<5;i++) { printf("The period for length %d is : %lf\n",i+1, T[i]); } getch(); return 0; } bila compile takde error tapi result dapat salah..output dia macam ni: Enter the value of period 1 to find the length: 10 Enter the value of period 2 to find the length: 20 Enter the value of period 3 to find the length: 30 Enter the value of period 4 to find the length: 40 Enter the value of period 5 to find the length: 50 The length for period 1 is : 24.849021 The length for period 2 is : 99.396085 The length for period 3 is : 223.641190 The length for period 4 is : 397.584338 The length for period 5 is : 621.225528 Enter the value of length 1 to find the period: 24.849021 Enter the value of length 2 to find the period: 99.396085 Enter the value of length 3 to find the period: 223.641190 Enter the value of length 4 to find the period: 397.584338 Enter the value of length 5 to find the period: 621.225528 The period for length 1 is : 621.225528--->sepatutnya dapat 10 balik :wacko: The period for length 2 is : 20.000000 The period for length 3 is : 30.000000 The period for length 4 is : 40.000000 The period for length 5 is : 50.000000aku compile guna dev-c++..puas aku memikirkan apa problem nye code nih.sape2 yg pakar tu mintak tolong ye.. Edited November 3, 2007 by fl1pfl0p Share this post Link to post Share on other sites
encik pot pet 0 Report post Posted November 3, 2007 double T[4],l[4]; kena kasi cukup la Share this post Link to post Share on other sites
fl1pfl0p 0 Report post Posted November 3, 2007 err..tak paham la encik pot pet .boleh terangkan lebih detail tak apa yg tak cukup? .sori la saya ni c ni baru lagi.. Share this post Link to post Share on other sites
encik pot pet 0 Report post Posted November 3, 2007 (edited) awak nak guna 5 values kan?oleh yg demikian,double T[5],l[5];nak access, T[0].T[1],..,T[4] = 5 elemenjgn konfius Edited November 3, 2007 by encik pot pet Share this post Link to post Share on other sites
fl1pfl0p 0 Report post Posted November 3, 2007 err..tak paham la encik pot pet .boleh terangkan lebih detail tak apa yg tak cukup? .sori la saya ni c ni baru lagi..owh..ok saya dah dapat .. saya tukar jadi double T[5],l[5]; dapat result betul.tapi kan kenapa double T[4],l[4]; tak dapat result betul. bukan ke cukup 5 array iaitu T[0] sampai T[4] .boleh tak terangkan kenapa? Share this post Link to post Share on other sites
encik pot pet 0 Report post Posted November 3, 2007 awk dah konfius.. pegi baca pasal array balik Share this post Link to post Share on other sites
fl1pfl0p 0 Report post Posted November 3, 2007 ok ..saya baca balik nnt.. terima kasih byk2 sebab sudi tolong kalo tidak sy konfius smpi bila2.. Share this post Link to post Share on other sites