TheAlgorithms/C++
1.0.0
All the algorithms implemented in C++
Loading...
Searching...
No Matches
searching_of_element_in_dynamic_array.cpp
1
/*
2
*this program is use to find any elemet in any row with variable array size
3
*aplication of pointer is use in it
4
*important point start from here to:
5
*the index value of array can be go to 1 to 100000
6
*check till array[1000]
7
*end here
8
*how to work example:
9
**Question:
10
***number of array 2
11
***quarry 3
12
***array 1 is {1 2 3 4 5}
13
***array 2 is {6 7}
14
****i) what is 2nd element in 1st array
15
****ii) what is 1st element in 2nd array
16
****iii) what is 5th element in 1st array
17
*****output:
18
*****Enter Number of array you want to Store : 2
19
*****Enter Number of Question or Quary you want to do Related to Array : 3
20
*****Enter number of element in 1 rows : 5
21
*****Enter the element of Array 1 2 3 4 5
22
*****Enter number of element in 2 rows : 2
23
*****Enter the element of Array 6 7
24
*****enter the number of row which element You want to find : 1
25
*****enter the position of element which You want to find : 2
26
*****The element is 2
27
*****enter the number of row which element You want to find : 2
28
*****enter the position of element which You want to find : 1
29
*****The element is 6
30
*****enter the number of row which element You want to find : 1
31
*****enter the position of element which You want to find : 5
32
*****The element is 5
33
*/
34
#include <iostream>
35
36
// this is main fuction
37
// ***
38
int
main
() {
39
int64_t r, mr = 0, x, q, i, z;
40
std::cout <<
"Enter Number of array you want to Store :"
;
41
std::cin >> x;
42
std::cout <<
"Enter Number of "
;
43
std::cout <<
"Question or Quary you "
;
44
std::cout <<
"want to do Related to Array :"
;
45
std::cin >> q;
46
// create a Array in run time because use can
47
// change the size of each array which he/she is going to store
48
// create a 2D array
49
int
** ar =
new
int
*[x]();
50
// this for loop is use for entering different variable size array
51
// ***
52
for
(r = 0; r < x; r++) {
53
std::cout <<
"Enter number of element in "
<< r + 1 <<
" rows :"
;
54
std::cin >> mr;
55
// creating a 1D array
56
int
* ac =
new
int
[mr]();
57
std::cout <<
"Enter the element of Array "
;
58
// this for loop is use for storing values in array
59
// ***
60
for
(i = 0; i < mr; i++) {
61
// entering the value of rows in array in Horizontal
62
std::cin >> ac[i];
63
}
64
// Change the position of Array so that new arrays entery will be done
65
ar[r] = ac;
66
}
67
// this for loop is use for display result of querry
68
// ***
69
for
(z = 0; z < q; z++) {
70
int64_t r1 = 0, q1 = 0;
71
std::cout <<
"enter the number of row which element you want to find :"
;
72
std::cin >> r1;
73
r1 = r1 - 1;
74
std::cout <<
"enter the position of element which you want to find :"
;
75
std::cin >> q1;
76
q1 = q1 - 1;
77
// use this to find desire position of element in desire array
78
std::cout <<
"The element is "
<< ar[r1][q1] << std::endl;
79
}
80
}
main
int main()
Main function.
Definition
generate_parentheses.cpp:110
dynamic_programming
searching_of_element_in_dynamic_array.cpp
Generated by
1.12.0