Write a C++ program to create a new array containing the middle elements from the two given arrays of integers, each length 5

  • برمجة سي بلس بلس
  • برمجة

Write a C++ program to create a new array containing the middle elements from the two given arrays of integers, each length 5

Sample Output:

New array:
20 -20

الأجوبة

#include <iostream>
using namespace std;

int *test(int nums1[], int nums2[]) {
   
    static int  max_array[] = { nums1[2], nums2[2] };
    return max_array;
}

int main () {
   // a pointer to an int.
   int *p;
   int nums1[] = {0, 10, 20, 30, 40};	
   int nums2[] = {0, -10, -20, -30, -40};	
   
     
   p = test(nums1, nums2);
   
   cout << "\nNew array: " << endl;
   for ( int i = 0; i < 2; i++ ) {
      cout << *(p + i) << " ";
   }

   return 0;
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...