Update searching_of_element_in_dynamic_array.cpp

This commit is contained in:
Faizan Ahamed 2020-04-21 20:23:36 +05:30 committed by GitHub
parent bfe50003d1
commit 52782f57f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,37 +1,39 @@
/* /*
this program is use to find any elemet in any row with variable array size *this program is use to find any elemet in any row with variable array size
aplication of pointer is use in it *aplication of pointer is use in it
important point start from here to: *important point start from here to:
the index value of array can be go to 1 to 100000 *the index value of array can be go to 1 to 100000
check till array[1000] *check till array[1000]
end here *end here
how to work example: *how to work example:
Question: **Question:
number of array 2 ***number of array 2
quarry 3 ***quarry 3
array 1 is {1 2 3 4 5} ***array 1 is {1 2 3 4 5}
array 2 is {6 7} ***array 2 is {6 7}
i) what is 2nd element in 1st array ****i) what is 2nd element in 1st array
ii) what is 1st element in 2nd array ****ii) what is 1st element in 2nd array
iii) what is 5th element in 1st array ****iii) what is 5th element in 1st array
output: *****output:
Enter Number of array you want to Store : 2 *****Enter Number of array you want to Store : 2
Enter Number of Question or Quary you want to do Related to Array : 3 *****Enter Number of Question or Quary you want to do Related to Array : 3
Enter number of element in 1 rows : 5 *****Enter number of element in 1 rows : 5
Enter the element of Array 1 2 3 4 5 *****Enter the element of Array 1 2 3 4 5
Enter number of element in 2 rows : 2 *****Enter number of element in 2 rows : 2
Enter the element of Array 6 7 *****Enter the element of Array 6 7
enter the number of row which element You want to find : 1 *****enter the number of row which element You want to find : 1
enter the position of element which You want to find : 2 *****enter the position of element which You want to find : 2
The element is 2 *****The element is 2
enter the number of row which element You want to find : 2 *****enter the number of row which element You want to find : 2
enter the position of element which You want to find : 1 *****enter the position of element which You want to find : 1
The element is 6 *****The element is 6
enter the number of row which element You want to find : 1 *****enter the number of row which element You want to find : 1
enter the position of element which You want to find : 5 *****enter the position of element which You want to find : 5
The element is 5 *****The element is 5
*/ */
#include <iostream> #include <iostream>
// this is main fuction
// ***
int main() { int main() {
int64_t 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 :";
@ -44,12 +46,16 @@ std::cin >> q;
// change the size of each array which he/she is going to store // change the size of each array which he/she is going to store
// create a 2D array // create a 2D array
int** ar = new int* [x](); int** ar = new int* [x]();
// this for loop is use for entering different variable size array
// ***
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 ";
// this for loop is use for storing values in 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];
@ -57,6 +63,8 @@ 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;
} }
// this for loop is use for display result of querry
// ***
for (z = 0; z < q; z++) { for (z = 0; z < q; z++) {
int64_t 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 :";