Guruh: 082-22-sdio’




Download 175,21 Kb.
Sana21.05.2024
Hajmi175,21 Kb.
#247955
Bog'liq
Dasturlash1


MUHAMMAD AL-XORAZMIY NOMIDAGI
TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI.



Amaliy ish


Guruh:082-22-SDIo’
Topshirdi: Toirov.S
Fan: Dasturlash 2


Toshkent – 2024


1-masala: Ro‘yxatning nusxasini qurish, lekin teskari tartibda
#include
void reverseArray(int arr[], int n) {
int start = 0;
int end = n - 1;
int temp;
while (start < end) {
temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
start++;
end--;
}
}
int main() {
int arr[] = {1, 2, 3, 4, 5, 6, 7};
int n = sizeof(arr) / sizeof(arr[0]);
printf("Boshlang'ich ro'yxat: ");
for (int i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
printf("\n");
int reversedArr[n];
for (int i = 0; i < n; i++) {
reversedArr[i] = arr[n - 1 - i];
}
printf("Teskari tartibdagi ro'yxat: ");
for (int i = 0; i < n; i++) {
printf("%d ", reversedArr[i]);
}
printf("\n");
return 0;
}

Masalani yechish uchun men C dasturlash tilidan foydalandim.


Dasturni include kutbxonasini chaqirishdan boshladik kegin asosiy funksiya int main() funksaysi arrayga massifga sonlar berdik massifni uzunligini aniqlab reverseArray funksiyaga swap
yani joyini alamshtirish funksyaga jonatdik va natijani printf orqali ekranga chiqardik.

Download 175,21 Kb.




Download 175,21 Kb.