Sayfullayev Sohibjon iat (19-15) Domla qaytadan ishlab chiqdim qo’ldan kelgancha


Download 20.78 Kb.
Sana16.06.2020
Hajmi20.78 Kb.
#119420
Bog'liq
2-amaliy dasturlash


Sayfullayev Sohibjon IAT (19-15)

Domla qaytadan ishlab chiqdim qo’ldan kelgancha.

1. Ihtiyoriy n ta sonning yig‘indisini hisoblash funksiyasi tuzilsin.

#include

using namespace std;

void summa(int n)

{

float sum = 0,a;



for(int i = 1; i <= n; i++)

{cin>>a;sum+=a;}

cout<

}

int main()



{

int n;


cin >> n;

summa(n);

return 0;

}

2. Ihtiyoriy n ta sonning maksimumini topish funksiyasi tuzilsin.



#include

using namespace std;

void maximum(int n)

{

int max;bool x=true;cin>>a;



if(x){max=a;x=false;}

for(int =0;i>a;if(a>max)max=a;}

cout<

}

int main()



{

int a,n,max;

cout << "n = "; cin >> n;

maximum(n);

return 0;

}

3. Ikkita uchburchak uchlarining koordinatalari bilan berilgan. Bu uchburchaklardan qaysi birining yuzasi katta ekanligini aniqlovchi funksiya tuzilsin.



#include

#include "cmath"

using namespace std;

int Yuza(float a1,float b1,float c1,float a2,float b2,float c2)

{

float p1,p2,s1,s2;



p1 = (a1 + b1 + c1) / 2;

s1 = sqrt(p1*(p1 - a1)*(p1 - b1)*(p1 - c1));

p2 = (a2 + b2 + c2) / 2;

s2 = sqrt(p2*(p2 - a2)*(p2 - b2)*(p2 - c2));

return (s1 > s2) ? 1 : 2;

}

int main()



{

float x1,x2,x3,y1,y2,y3,a1,b1,c1,a2,b2,c2;

cout << "1 - uchburchak uchlari koordinatalarini kiriting:" << endl;

cout << "x1 = "; cin >> x1;

cout << "y1 = "; cin >> y1;

cout << "x2 = "; cin >> x2;

cout << "y2 = "; cin >> y2;

cout << "x3 = "; cin >> x3;

cout << "y3 = "; cin >> y3;

//1 - uchburchak tomonlari:

a1 = sqrt((x1 - x3)*(x1 - x3) + (y1 - y3)*(y1 - y3));

b1 = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));

c1 = sqrt((x2 - x3)*(x2 - x3) + (y2 - y3)*(y2 - y3));

cout << "x1 = "; cin >> x1;

cout << "y1 = "; cin >> y1;

cout << "x2 = "; cin >> x2;

cout << "y2 = "; cin >> y2;

cout << "x3 = "; cin >> x3;

cout << "y3 = "; cin >> y3;

//2 - uchburchak tomonlari

a2 = sqrt((x1 - x3)*(x1 - x3) + (y1 - y3)*(y1 - y3));

b2 = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));

c2 = sqrt((x2 - x3)*(x2 - x3) + (y2 - y3)*(y2 - y3));

cout << Yuza(a1,b1,c1,a2,b2,c2) << " - uchburchakning yuzasi katta";

return 0;

}


4.

n natural soni va n ta sonlardan iborat ketma-ketlik berilgan. Ketma-ketlikdagi ishora almashinishlar sonini aniqlash funksiyasi tuzilsin.


#include

using namespace std;

void ishora(int a,int b)

{

return (a * b < 0) ? 1 : 0;



}

int main()

{

int n,a,b,s=0;



cout << "n = "; cin >> n;

cin >> a;

for(int i = 2; i <= n; i++)

{

cin >> b;



s += ishora(a,b);

a = b;


}

cout << s;

return 0;

}

7. Tekislikda a, b, c va d kesmalar berilgan. Ularning har bir uchtasidan uchburchak qurish mumkinligini aniqlaydigan mantiqiy Uchburchak() funksiya tuzilsin. Agar Uchburchak() funksiyasi birorta uchlik uchun true qiymat qaytarsa, shu uchlikdan hosil bo‘lgan uchburchakning yuzasini hisoblovchi haqiqiy turdagi Uchburchak_Yuzasi() funksiya tuzilsin.



#include

#include "cmath"

using namespace std;

bool Uchburchak(float a,float b,float c)

{

return (a + b > c && b + c > a && a + c > b);



}

float Uchburchak_Yuzasi(float a,float b,float c)

{

float p,s;



p = (a + b + c) / 2;

s = sqrt(p * (p - a) * (p - b) * (p - c));

return s;

}

int main()



{

float a,b,c,d;

bool s1,s2,s3;

cin >> a >> b >> c >> d;

s1 = Uchburchak(a,b,c);

s2 = Uchburchak(a,c,d);

s3 = Uchburchak(b,c,d);

if(s1)


cout << "Uchburchak yuzasi - " << Uchburchak_Yuzasi(a,b,c) << endl;

if(s2)


cout << "Uchburchak yuzasi - " << Uchburchak_Yuzasi(a,c,d) << endl;

if(s3)


cout << "Uchburchak yuzasi - " << Uchburchak_Yuzasi(b,c,d) << endl;

return 0;

}


8.

Butun a, b, p, q (b0) parametriga ega qisqart(a,b,p,q) funksiya a/b kasrni qisqarmaydigan p/q ko‘rinishiga olib kelsin.

#include

using namespace std;

void qisqart(int a,int b,int p,int q)

{

int ekub;



while(a != b)

{

if(a > b)



a -= b;

else b -= a;

}

p /= a; q /= b;



cout << "natija = " << p << "/" << q;

}

int main()



{

int a,b,p,q;

cin >> a >> b;

p = a; q = b;

qisqart(a,b,p,q);

return 0;

}


9.

Uchburchak a, b va c tomonlari bilan berilgan. Uchburchakning medianalaridan iborat uchburchakning medianalari topilsin. (Izoh: uchburchakning a tomoniga o‘tkazilgan mediana ga teng).

#include

#include "cmath"

using namespace std;

float mediana(float x,float y,float z)

{

float med;



med = sqrt(2*(x*x + y*y) - z*z) / 2;

return med;

}

int main()



{

float a,b,c;

cout<<”a=”;cin>>a; cout<<”b=”;cin>>b;

cout<<”c=”;cin>>c;

cout << "a tomoniga tushirilgan mediana - " << mediana(b,c,a) << endl;

cout << "b tomoniga tushirilgan mediana - " << mediana(a,c,b) << endl;

cout << "c tomoniga tushirilgan mediana - " << mediana(a,b,c) << endl;

return 0;



}

Download 20.78 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling