Topshiriq 5


Download 196.5 Kb.
Sana18.02.2023
Hajmi196.5 Kb.
#1209331
Bog'liq
s8dEzpLhU29ohCzRHj4-PfWuTUvaAWfT


Topshiriq 5
Xisobot quyidagilardan iborat bo’lishi kerak:

  1. Talabaning ism va familiyasi;

  2. Berilgan topshiriq raqami va undagi vazifa ko’chirib yozilishi kerak;

  3. Dastur kodi va olingan natija.

KI22-01 guruhi talabasi


Jumayev Qurbonmurod



        1. Fibonachi ketma ketligining N inchi hadini qaytaruvchi Fibonachi(int n) funksiyani yarating.

#include
using namespace std;
int main() {
int n, t1 = 0, t2 = 1, nextTerm = 0;
cin >> n;
for (int i = 1; i <= n; ++i) {
if(i == 1) {
cout << t1 << ", ";
continue;
}
if(i == 2) {
cout << t2 << ", ";
continue;
}
nextTerm = t1 + t2;
t1 = t2;
t2 = nextTerm;
cout << nextTerm << ", ";
}
return 0;
}
Natija:


        1. Berilgan massivni saralovchi Sort(int a[]) funksiyani yarating.

#include
using namespace std;
void sorting(int n){
int a[n];
for(int i=0;i
cin>>a[i];
}
for(int i=0;i
for(int j=0;j
if(a[i]
int b=a[j];
a[j]=a[i];
a[i]=b;
}
}
}
for(int i=0;i
cout<
}
}
int main(){
int n;
cin>>n;
sorting(n);
}

        1. Uchburchak sinfini yarating . Unda a,b,c tomonlarni aniqlovchi aragumentlar hamda uchburchakning burchaklarini(gradusda) qaytaruchi BurchakA(),BurchakB(),BurchakC() , yuzini qaytaruvchi Yuza(),medianasini qaytaruvchi Mediana() , turini qaytaruvchi Turi()(bunda qiymat sifatida “to’g’ri burchakli”, “o’tkir burchakli” ,”teng yonli” va hkz lar qaytariladi) funksiyalar bo’lsin.



#include
using namespace std;
class uchburchak{
public:
double a,b,c,S;
uchburchak(){ a=0; b=0; c=0; S=0; }
uchburchak(double a,double b, double c, double S){
this->a=a;
this->b=b;
this->c=c;
this->S=S;
}
void burchakA(){
cout<<"burchak A"<
}
void burchakB(){
cout<<"burchak B"<
}
void burchakC(){
cout<<"burchak C"<
}
void Yuza(){
cout<<"yuza "<
}
void turi(){
if(2*S/b/a==1||2*S/c/a==1||2*S/b/c==1)
cout<<"to'g'ri burchakli"<
if(a==b&&a==c&&c==b) cout<<"ten tomonli"<
else if(a==b||a==c||c==b) cout<<"ten yonli"<
else cout<
}
void mediana(){
cout<<"mediana A = "<<1./2*sqrt(2*b*b+2*c*c-a*a)<
cout<<"mediana B = "<<1./2*sqrt(2*a*a+2*c*c-b*b)<
cout<<"mediana C = "<<1./2*sqrt(2*b*b+2*a*a-c*c)<
}
};
int main(){
double a,b,c,S,p;
cin>>a>>b>>c;
p=(a+b+c)/2;
S=sqrt(p*(p-a)*(p-b)*(p-c));
uchburchak u(a,b,c,S);
u.burchakA();
u.burchakB();
u.burchakC();
u.Yuza();
u.turi();
u.mediana();
}

        1. To’rburchak sinfini yarating . Unda a,b,c,d tomonlarni aniqlovchi aragumentlar hamda to’rtburchakning burchaklarini(gradusda) qaytaruchi BurchakA(),BurchakB(),BurchakC() ,BurchakD(), yuzini qaytaruvchi Yuza(),dioganallarini qaytaruvchi , turini qaytaruvchi Turi()(bunda qiymat sifatida “to’g’ri burchakli”, “romb” ,”trapetsiya” va hkz lar qaytariladi) funksiyalar bo’lsin.

class Rectangle:
def init(self, a, b,c,d):
self.a = a
self.b = b

def perimeter(self):
return 2 * (self.a+self.b)


def area(self):
return self.a*self.b
Download 196.5 Kb.

Do'stlaringiz bilan baham:




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