Isroilova Shirin


Download 53.06 Kb.
Sana17.02.2023
Hajmi53.06 Kb.
#1205237
Bog'liq
1676359377 (1)




Isroilova Shirin
2-amali ish

7. ikkita N o'lchamli massiv berilgan.Undagi mos elimentlarini ko'paytiring va natijani uchinchi massivga yozing


#include


using namespace std;
void alternateMerge(int arr1[], int arr2[], int n1, int n2,
int arr3[])
{
int i = 0, j = 0, k = 0;

while (i < n1 && j < n2) {


arr3[k++] = arr1[i++];
arr3[k++] = arr2[j++];
}

while (i < n1)


arr3[k++] = arr1[i++];

while (j < n2)


arr3[k++] = arr2[j++];
}

int main()


{
int arr1[] = { 1, 3, 5, 7, 9, 11 };
int n1 = sizeof(arr1) / sizeof(arr1[0]);
cout<<"Birinchi massiv:"<for (int i = 0; i < n1 ; i++)
cout<cout<int arr2[] = { 2, 4, 6, 8 };
int n2 = sizeof(arr2) / sizeof(arr2[0]);
cout<<"Ikkinchi massiv:"<for (int i = 0; i < n2 ; i++)
cout<cout<int arr3[n1 + n2];
alternateMerge(arr1, arr2, n1, n2, arr3);

cout << "Birlashgandan keyingi massiv:" << endl;


for (int i = 0; i < n1 + n2; i++)
cout << arr3[i] << " ";

return 0;


}



Download 53.06 Kb.

Do'stlaringiz bilan baham:




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