|
Mavzu: Mavzu: Dasturlashda funksiya va modullarni qo‘llash reja
|
bet | 4/5 | Sana | 04.01.2024 | Hajmi | 14,36 Kb. | | #130049 |
Bog'liq Mavzu Mavzu Dasturlashda funksiya va modullarni qo‘llash reja-fayllar.org# include # include # include // учбурчак томонини топиш функцияси float line (float x1, float x2, float y1, float y2) { (float) p = sqrt ((x1-x2)*(x1-x2)+ (y1-y2)*(y1-y2)); return p; } // учбурчак куриб буладими? функцияси int uch ( float a, float b, float c) { if ( a+b>c && b+c>a && c+a>b ) return 1; else return 0; } // учбурчакнинг юзини топиш функцияси float s (float a, float b, float c) { float p, s1; p = ( a + b + c ) / 2; s1 = sqrt (p*(p-a)*(p-b)*(p-c)); return s1; } // dastur davomi void main ( ) { float x1, x2, x3, y1, y2, y3, p1, p2, p3, yuza; cin >> x1>> x2>> x3>> y1>> y2>> y3; clrscr ( ); p1 = line (x1, x2, y1, y2); p2 = line (x1, x3, y1, y3); p3 = line (x2, x3, y2, y3); t = uch (p1, p2, p3); if ( t = = 1) { yuza = s ( p1, p2, p3); cout << “yuza = ”<< yuza << endl; else cout <<”uchburchak qurib bo’lmaydi !!!”<< endl; } getch ( ); } Rekursiya holatiga misollar: f = n! hisoblash dasturi: # include int fac (int i) { return i<=1 ? 1 : i * fac ( i-1); } void main ( ) { int n, f ; cout << “Sonni kiriting =”; cin >> n ; f = fac ( n ); cout << “ f = “<< f < Rekursiya holatiga 2-misol: Fibonachi sonlarini hosil qilish dasturi. Fibonachi sonlari quyidagicha topiladi: f0 = 1; f1 = 1; f2 = f1 + f0; ……. fn = fn-1 + fn-2 9-o’rindagi Fibonachi sonini topish kerak. # include int fib ( int n) { if ( n<=2) return 1; else return ( fib (n-2) + fib (n-1)); } void main ( ) { int n, f ; cout << “Sonni kiriting =”; cin >> n ; f = fib ( n ); cout << “ f = “<< f < Z = ( a⁵ + a⁻⁴) / ( 2*aⁿ) hisoblash dasturi tuzilsin. Bu erda y = xⁿ funksiya sifatida tashkil etilsin. # include float dar ( float x, int n) { float y = 1; for ( int i = 0; i<=n; i++) y = y * x; return y; } void main ( ) { int n = 10; float a, z; cin >> a; z = (dar ( a, 5) + dar (1/a, 4)) / ( 2* dar ( a, n)); cout << “ z = “ << z << endl; } Masalan: 1) double multi ( float x) { return x*x*x; } 2) double multi ( float x, float y) { return x*x*y; } 3) double multi ( float x, float y, float z) { return x*y*z; }
|
| |