Skip to content

Commit 1415e08

Browse files
authored
Update 05 inserting an element.c
1 parent 96df9cb commit 1415e08

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

Array/05 inserting an element.c

+18-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ struct Array
99
void Display(struct Array arr)
1010
{
1111
int i;
12+
cout<<"printing all the elements "<<endl;
1213
for (i = 0; i < arr.length; i++)
1314
cout << arr.A[i] << " ";
1415
}
@@ -32,11 +33,22 @@ void Insert(struct Array* arr, int index, int x) // the index at which we want t
3233

3334
}
3435

35-
int main()
36-
{
37-
struct Array arr1 = { {2,3,4,5,6},10,5 };
38-
Add(&arr1, 10);
39-
Insert(&arr1, 0, 12);
40-
Display(arr1);
36+
int main() {
37+
int no;
38+
struct Array arr;
39+
cout << "Enter the size of the array " << endl;
40+
cin >> arr.size;
41+
arr.A = new int[arr.size];
42+
arr.length = 0;
43+
cout << "Enter the length of array" << endl;
44+
cin >> no;
45+
cout << "Enter all the elements of array" << endl;
46+
for (int i = 0; i < no; i++)
47+
cin >> arr.A[i];
48+
arr.length = no;
49+
Add(&arr, 10);
50+
Insert(&arr,3,25);
51+
Display(arr);
52+
4153
return 0;
4254
}

0 commit comments

Comments
 (0)