1-topshiriq nxn matritsaning pastki chap uchburchagidagi elementlaridan vektor hosil qiling



Download 3,26 Mb.
bet1/2
Sana21.07.2022
Hajmi3,26 Mb.
#833068
  1   2
Bog'liq
MTA 1


1-topshiriq
1.nxn matritsaning pastki chap uchburchagidagi elementlaridan vektor hosil qiling.
#include
#include
#include
using namespace std;
int main() {
int n; n=4;
int a[n][n];
vectorvk;
for(int i=0; ifor(int j=0; ja[i][j]=rand()%9;
if(i>j)vk.push_back(a[i][j]);
}
}
cout<<"Massiv:\n";
for(int i=0; ifor(int j=0; jcout<cout<}
cout<<"******* \n Vektor: \n";
for(int i=0; icout<return 0;
}


1.1- topshiriq







#include
using namespace std;
int main(){
double x, y, e=2.7182818285, pi=3.1415926536;
cout<<"x=";
cin>>x;
y=pow((pow(x, 3)+cos(pow(abs(pow(x, 3)), 1/2))), 1/5)+(pow(e, x))/(cos(3*x+pi/15));
cout<<"y="<}















2-topshiriq
Ketma-ket qidiruv usulidan foydalanib ro’yhatda har ikkinchi elementni qidiring va taqqoslashlar sonini aniqlang.
#include
using namespace std;
int main(){
int n;
cout<<"n=";
cin>>n;
int k[n];
for(int i=0;icin>>k[i];
int low = 0;
int hi = n-1;
int j=0;
while (low <= hi){
int mid = (low + hi) / 2;
j++;
if (k[1] == k[mid]){
cout<<"qidirilayotgan element "<return 0;
}
if (k[1] < k[mid])
hi = mid - 1;
else low = mid + 1;
}
return 0;
}


3-topshiriq
Talabalar familiyalarini alifbo tartibida
#include
#include
using namespace std;
struct ORIN{ int t; string FIO;}; int q=0;
void qs(ORIN *a,int first,int last){
int i = first, j = last;ORIN x =a[(first + last) / 2]; do {
while (a[i].FIO < x.FIO) i++; while (a[j].FIO > x.FIO) j--; if(i <= j) {
if (i < j){ swap(a[i], a[j]);q++;} i++; j--;}
} while (i <= j); if (i < last)
qs(a,i,last); if (first < j) qs(a,first,j);}
int main(int args, char *argv[])
{
int n;cout<<"Talabalar sonini kiriting: ";
cin>>n; ORIN nomer[n];
cout<<"Namuna: Toshpolatov_Shaxzodbek"<for(int i=0;inomer[i].t=i+1;
cin>>nomer[i].FIO;}
qs(nomer,0,n-1);
for(int i=0;icout<cout<}



3.1-topshiriq

“22”, “26”, “14”, “52”, “76”, “45”, “84”, “75”, “15” berilgan butun sonlarni

pufakchali saralash usuli orqali dasturi ishlab chiqilsin va taxlil qilinsin.

#include

using namespace std;

void swap(int *xp, int *yp){

int temp=*xp; *xp=*yp; *yp=temp; }

void p_saralash(int arr[], int n){ int i, j;

for(i=0; i

if(arr[j]>arr[j+1]) swap(&arr[j],&arr[j+1]); }

void printArray(int arr[], int size ){ int i;

for(i=0; i

cout<

cout<

int main(){

int m;

cout<<"Massiv elementlari soni: ";

cin>>m; int arr[m]; cout<<"Massiv elementlarni kiriting: ";

for(int k=0; k

cin>>arr[k];

int n=sizeof(arr)/sizeof(arr[0]);

p_saralash(arr,n);

cout<<"Saralangan massiv elementlari: ";

printArray(arr,n);

return 0; }



4-topshiriq
Sonni raqamlar yig`indisini topuvchi rekursiv funksiya tuzing.
#include
#include
using namespace std;
int Raqam_Yigindi(int n) {
int sum=0, r;
for(int i=0; i<=n; i++)
if(n!=0){
r=n%10;
sum += fabs(r) ;
n=n/10 ;
}
return sum ;
}
int main()
{
int n;
cout<<"Sonni kiriting: " ; cin>>n ;
cout <<"Sonning raqamlari yig'indisi: " << Raqam_Yigindi(n);
return 0;
}



4.1-topshiriq
Berilgan a va b sonlarining EKUKini topuvchi rekursiv funksiya tuzing.
#include
using namespace std;
long EKUK(long a, long b) {
if (b != 0) {
long long c = a % b;
a = b;
b = c;
return EKUK(a, b);
}
} int main()
{ int a,b;
cout << "A="; cin>>a;
cout << "B="; cin>>b;
cout << "EKUK(" << a << ";" << b << ")=" << a*b*1./EKUK(a,b) << endl;
return 0;
}

5-topshiriq
List elementlari orasidan k indeksdagi elementni topuvchi dastur tuzing.
#include
using namespace std;
int main()
{
list a;
long n,i,x;
cin>>n;
for (i=0; i {
cin>>x;
a.push_back(x);
}
int k; cin>>k;
int cnt=0;
for (auto i:a){
if (cnt==k-1) cout << i << endl;
cnt++;
}
return 0;
}



6-topshiriq
Talaba sinfini dasturda qo‘1lang. Sinfda parametrsiz va parametrli konstruktor, kiritish va chiqarish usullari yaratilsin.

#include


using namespace std;
struct Talaba{
string familiya,ism,mutaxasislik;
int kurs;};
int main()
{
Talaba T[1000];
int n;
cout<<"Talabalar sonini kiriting: ";
cin>>n;
for(int i=1; i<=n; i++)
{ cout<<"Talabani familiyasini kiriting: ";
cin>>T[i].familiya;
cout<<"Talabaning ismini kiriting: ";
cin>>T[i].ism;
cout<<"Talabaning mutaxasisligini kiriting: ";
cin>>T[i].mutaxasislik;
cout<<"Talabaning kursini kiriting: ";
cin>>T[i].kurs; cout<string S;
cout<<"So'ralgan talabaning familiyasini kiriting:";cin>>S;
for(int i=1; i<=n; i++)
{
if(T[i].familiya==S){
cout<<"Talabaning F.I:"<cout<<"Mutaxasislik:"<cout<<"Kursi:"<}else
cout<<"Bunday familiyaga ega talaba mavjud emas!";
break; }
}



6.1-topshiriq
Nuqta sinfini yarating. Bu sinf asosida uchburchak sinfini yarating va dasturda qo‘llang. Bu sinfda perimetr, y uzani hisoblash va uchburchakni chizish usullari mavjud bo‘lsin.
#include
using namespace std;
class nuqta {
long a , b , c;
double p , s ;
public:
nuqta(){};
nuqta(long A, long B, long C){
nuqta::a = A;
nuqta::b = B;
nuqta::c = C;
nuqta::p = (A+B+C);
nuqta::s = sqrt((p*1./2-a)*(p*1./2-b)*(p*1./2-c));
}
void chiqarish(){
cout << "Uchburchak qiymatlari"<cout << "a=" << a << endl;
cout << "b=" << b << endl;
cout << "c=" << c << endl;
cout << "p=" << p << endl;
cout << "s=" << s << endl;
cout << endl;
}};
class uchburchak{
public:
static void uchburchak_kiritish(struct nuqta Triangle[], int n){
long a , b , c;
for (int i=0;icout << "Uchburchak tomonlarini kiriting: " << endl;
cout << "a="; cin >> a;
cout << "b="; cin >> b;
cout << "c="; cin >> c;
cout << endl;
Triangle[i] = nuqta(a,b,c); }}
static void uchburchak_chiqarish(struct nuqta Triangle[], int n){
for (int i=0;iTriangle[i].chiqarish(); }
};
int main() {
nuqta Triangle[] = {
nuqta(6,4,3),
nuqta(6,6,6),
nuqta(6,7,5), };
uchburchak::uchburchak_chiqarish(Triangle, 3);
uchburchak::uchburchak_kiritish(Triangle,1);
uchburchak::uchburchak_chiqarish(Triangle,3);
}

7-topshiriq
Bog’langan ro‟yhat har ikkinchi elementi o‟chirilsin.
#include #include
using namespace std;
template
class List
{
private:
unsigned int size;
class Node
{
public:
T data;
Node *Pnext;
}*Head;
void pop_front(T);
public:
List()
{
this->size=0;
this->Head=NULL;
}
List(T dat)
{
Node*p=new Node;
p->data=dat;
p->Pnext=NULL;
this->Head=p;
}
void push_back(T );
void push_front(T);
unsigned int size_();
void erase(T);
void print();
T &operator[](int index);
};
int main()
{
int n;
Listaz;
cout<<"Ro'yhatda nechta element bor:";
cin>>n;
for(int i=0;i{ int x;
cin>>x;
az.push_back(x);
}
vectordel;
for(int i=1;i{
del.push_back(az[i]);
}
for(int i=0;iaz.erase(del[i]);
az.print();
return 0;
}
template
void List::push_back(T data )
{
Node*p=new Node;
p->data=data;
p->Pnext=NULL;
if(!Head)
Head=p;
else
{
Node *tem=Head;
while(tem->Pnext)
tem=tem->Pnext;
tem->Pnext=p;
}
size++;
}
template
void List::print()
{
Node *p=this->Head;
while(p)
{
cout<
data<<" ";
p=p->Pnext;
}
cout<}
template
T&List::operator[](int index)
{
int cnt=0;
Node *p=Head;
while(cnt!=index)
{
p=p->Pnext;
cnt++;
}
return p->data;
}
template
void List::push_front(T data)
{
Node *p=new Node;
p->Pnext=Head;
p->data=data;
Head=p;
size++;
}
template
unsigned int List::size_()
{
return this->size;
}
template
void List::pop_front(T data)
{ Node *p=Head;
Head=p->Pnext;
delete p;
} template
void List::erase(T data)
{ Node *p=Head;
if(p->data==data)
{ this->pop_front(data);
size--;
return ;
} while((p->data!=data)&&p->Pnext)
p=p->Pnext;
if(p->data!=data)return;
Node *tem=Head;
while(tem->Pnext!=p)
tem=tem->Pnext;
tem->Pnext=p->Pnext;
size--;
delete p;
}



7.1-topshiriq
N ta doira berilgan. Bu doiralardan ustma-ust qo‗ygan holda piramida yig‗ilmoqda. Yig‗ishda ularning markazlari bitta nuqtada turishi lozim. Demak, n ta doira va ularning radiuslari berilgan. Agar ularni ustma-ust qo‗yganda tepadan qaraganda qaysi radiusli doiralarni ko‗rish mumkin.

Kiruvchi

Chiquvchi

6
6 2 1 5 3 4

6 5 4

6
1 2 3 4 5 6

6

#include
using namespace std;
int main()
{
stack a1,a2;
int n,x,i;
cin>>n;
for (i=0; i{
cin>>x;
a1.push(x);
}
int max=a1.top();
a1.pop();
a2.push(max);
while (!a1.empty())
{
if (a1.top()>=max) {
a2.push(a1.top());
a1.pop();
}else a1.pop();
}
while (!a2.empty())
{
cout << a2.top() << " ";
a2.pop();
}
return 0;
}



8-topshiriq
Ikkita ro‟yhat birlashtirilsin.
#include
#include
#define SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
using namespace std;
struct node {
char data;
struct node *next;
};
node *createList(char *arr, int n){
node *head, *p;
p = head = new node;
head->data = arr[0];
head->next = NULL;
for (int i = 1; i < n; ++i) {
p->next = new node;
p = p->next;
p->data = arr[i];
p->next = NULL;
}
return head;
}
void displayList(node *head){
while (head != NULL) {
cout << head->data << " ";
head = head->next;
}
cout << endl;
}
node *mergeSortedLists(node *head1, node *head2){
node *result = NULL;
if (head1 == NULL) {
return head2;
}
if (head2 == NULL) {
return head1;
}
if (head1->data < head2->data) {
result = head1;
result->next = mergeSortedLists(head1->next, head2);
} else {
result = head2;
result->next = mergeSortedLists(head1, head2->next);
}
return result;
}

int main(){


int n,m;
cout<<"1-ro'yxat elementlari soni: "; cin>>n;
char arr1[n];
cout<<"1-ro'yxat elementlarini kiriting: "<for (int i=0; icin>>arr1[i];
cout<<"2-ro'yxat elementlari soni: ";
cin>>m;
char arr2[n];
cout<<"2-ro'yxat elementlarini kiriting: "<for (int i=0; icin>>arr2[i];
node *head1, *head2, *result = NULL;
head1 = createList(arr1, SIZE(arr1));
head2 = createList(arr2, SIZE(arr2));
cout << " Birinchi tartiblangan ro'yxat:" << endl;
displayList(head1);
cout << " Ikkinchi tartiblangan ro'yxat:" << endl;
displayList(head2);
result = mergeSortedLists(head1, head2);
cout << " Yakuniy tartiblangan ro'yxat:" << endl;
displayList(result);
return 0;
}




Download 3,26 Mb.

Do'stlaringiz bilan baham:

  1   2




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

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish