Labaratoriya ish



Download 17,09 Kb.
Sana29.01.2022
Hajmi17,09 Kb.
#417733
Bog'liq
Labaratoriya ish C


Labaratoriya ish


  1. nxn matritasning pastki o’ng burchagidagi elementlaridan vector hosil qiling.

Yechim:
int main() {


int matrix[3][3] = {{1, 2, 3},
{4, 5, 6},
{7, 8, 9}};
int row = 3, col = 3;
int i, j;

for (i = 0; i < row; i++)


{
for (j = 0; j < col; j++)
{
if (i+j==3||i+j==4)
{
cout << "0" << " ";
}
else
cout << matrix[i][j] << " ";
}
cout << endl;
}
return 0;
}


  1. Navbat eng katta elementi topilsin undan keyin 0 joylashtrilsin.


  1. Ro’yhat n-inchi elementidan keyin yangi element qo’yilsin.



  1. nxn matritasning pastki o’ng burchagidagi elementlaridan vector hosil qiling.

Yechim:


int main() {
int matrix[3][3] = {{1, 2, 3},
{4, 5, 6},
{7, 8, 9}};
int row = 3, col = 3;
int i, j;

for (i = 0; i < row; i++)


{
for (j = 0; j < col; j++)
{
if (i+j==3||i+j==4)
{
cout << "0" << " ";
}
else
cout << matrix[i][j] << " ";
}
cout << endl;
}
return 0;
}


  1. Mashina raqamlari ro’yhati berilgan 345, 368, 876, 945, 564, 387, 230, Binar qidiruvdan foydalanib berilgan raqamli mashina qaysi joyda turganini toping.

Yechim:
#include

using namespace std;

int binarySearch(int arr[], int left, int right, int x) {


while (left <= right) {
int mid = left + (right - left) / 2;

if (arr[mid] == x) {


return mid;
} else if (arr[mid] < x) {
left = mid + 1;
} else {
right = mid - 1;
}
}

return -1;


}

int main() {


int myarr[10];
int num;
int output;
myarr = [345, 368, 876, 945, 564, 387, 230]
// cout << "Please enter 10 elements ASCENDING order" << endl;
// for (int i = 0; i < 10; i++) {
// cin >> myarr[i];
// }

cout << "Please enter an element to search" << endl;


cin >> num;

output = binarySearch(myarr, 0, 9, num);

if (output == -1) {
cout << "Bunday no'merdagi avtomobil topilmadi" << endl;
} else {
cout << "Avtomobil joy no'meri: " << output << endl;
}

return 0;


}



  1. Daraxt tugunlari haqiqiy sonlar bo’lsin, Yozuv berilgan kalit qiymatidan katta bo’lgan daraxt tugunlarini o’chiruvchi dastur tuzing.

Yechim:
#include

using namespace std;

struct node
{
int key;
struct node *left;
struct node *right;
};
node* removeOutsideRange(node *root, int max)
{
if (root == NULL)
return NULL;
root->left = removeOutsideRange(root->left, max);
root->right = removeOutsideRange(root->right, max);
if (root->key > max)
{
node *lChild = root->left;
delete root;
return lChild;
}
return root;
}
node* newNode(int num)
{
node* temp = new node;
temp->key = num;
temp->left = temp->right = NULL;
return temp;
}
node* insert(node* root, int key)
{
if (root == NULL)
return newNode(key);
if (root->key > key)
root->left = insert(root->left, key);
else
root->right = insert(root->right, key);
return root;
}
void inorderTraversal(node* root)
{
if (root)
{
inorderTraversal( root->left );
cout << root->key << " ";
inorderTraversal( root->right );
}
}

int main()


{
node* root = NULL;
root = insert(root, 6);
root = insert(root, 14);
root = insert(root, 8);
root = insert(root, 15);
root = insert(root, 13);
root = insert(root, 7);

cout << "Inorder traversal of the given tree is: ";


inorderTraversal(root);

root = removeOutsideRange(root, 13);

cout << "\nInorder traversal of the modified tree is: ";
inorderTraversal(root);

return 0;


}
Download 17,09 Kb.

Do'stlaringiz bilan baham:




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