Update searching_of_element_in_dynamic_Array.cpp

This commit is contained in:
faizan Ahamed 2020-04-21 01:03:38 +05:30 committed by GitHub
parent a3268742f3
commit 3621d2ee26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -33,35 +33,36 @@ The element is 5
*/ */
#include <iostream> #include <iostream>
int main() { int main() {
long long int r, mr = 0, x, q, i, z; int64_t r, mr = 0, x, q, i, z;
std::cout << "Enter Number of array you want to Store :"; std::cout << "Enter Number of array you want to Store :";
std::cin >> x; std::cin >> x;
std::cout << "Enter Number of Question or Quary you want to do Related to Array :"; std::cout << "Enter Number of Question or Quary you want to do Related to Array :";
std::cin >> q; std::cin >> q;
//create a Array in run time because use can change the size of each array which he/she is going to store // create a Array in run time because use can
//create a 2D array // change the size of each array which he/she is going to store
// create a 2D array
int** ar = new int* [x](); int** ar = new int* [x]();
for (r = 0; r < x; r++) { for (r = 0; r < x; r++) {
std::cout << "Enter number of element in " << r + 1 << " rows :"; std::cout << "Enter number of element in " << r + 1 << " rows :";
std::cin >> mr; std::cin >> mr;
//creating a 1D array // creating a 1D array
int* ac = new int[mr](); int* ac = new int[mr]();
std::cout << "Enter the element of Array "; std::cout << "Enter the element of Array ";
for (i = 0; i < mr; i++) { for (i = 0; i < mr; i++) {
//entering the value of rows in array in Horizontal // entering the value of rows in array in Horizontal
std::cin >> ac[i]; std::cin >> ac[i];
} }
//Change the position of Array so that new arrays entery will be done // Change the position of Array so that new arrays entery will be done
ar[r] = ac; ar[r] = ac;
} }
for (z = 0; z < q; z++) { for (z = 0; z < q; z++) {
long int r1 = 0, q1 = 0; int64_t r1 = 0, q1 = 0;
std::cout << "enter the number of row which element You want to find :"; std::cout << "enter the number of row which element You want to find :";
std::cin >> r1; std::cin >> r1;
r1 = r1 - 1; r1 = r1 - 1;
std::cout << "enter the position of element which You want to find :"; std::cout << "enter the position of element which You want to find :";
std::cin>> q1; std::cin>> q1;
q1 = q1 - 1; q1 = q1 - 1;
//use this to find desire position of element in desire array // use this to find desire position of element in desire array
std::cout <<"The element is "<< ar[r1][q1] <<std::endl; std::cout <<"The element is "<< ar[r1][q1] <<std::endl;
}} }}