Dynamic Memory Allocation, Array

Task 1: Declare two integer arrays, A and B, of size 5. Take user input for both arrays and determine whether the two arrays are identical or not. Two arrays are identical if both contain same values at same indices. Print “Identical” or “Not identical” based on your finding.


#include <iostream> using namespace std; int main() { // decleartion int *a, *b; a = new int[5]; b = new int[5]; // user input cout << "Enter A array: " << endl; for (int i = 0; i < 5; i++) { cin >> a[i]; } // user input cout << "\nEnter B array: " << endl; for (int i = 0; i < 5; i++) { cin >> b[i]; } int f = 0; // to idetify a & b array for (int i = 0; i < 5; i++) { if (a[i] != b[i]) { f = 1; break; } } if (f == 0) { cout << "\nIdentical" << endl; } else { cout << "\nNot Identical" << endl; } return 0; }


Task 2: Read 10 integers from the user and store them in an array. Take another integer from the user and check whether it is in the array (print “Found” in that case) or not (print “Not found”).


#include <iostream> using namespace std; int main() { int *p; p = new int[10]; cout << "Give 10 integer numbers in the array: " << endl; for (int i = 0; i < 10; i++) { cin >> p[i]; } int sn; // sn = searching number int found = 0; cout << "\n\nGive an integer number which wants to search? => "; cin >> sn; for (int i = 0; i < 10; i++) { if (p[i] == sn) { found = 1; break; } } if (found == 1) { cout << "\nFound" << endl; } else { cout << "\nNot Found" << endl; } return 0; }