1 | #include <stdio.h> | ||
2 | void main() | ||
3 | { | ||
4 | int vectorx[10]; | ||
5 | int i, n, pos, element, found = 0; | ||
6 | |||
7 | printf("Enter_Number of elements\n"); | ||
8 | scanf("%d", &n); | ||
9 | printf("Enter the elements\n"); | ||
10 | for (i = 0; i < n; i++) | ||
11 | { | ||
12 | scanf("%d", &vectorx[i]); | ||
13 | } | ||
14 | printf("Input_array elements are\n"); | ||
15 | for (i = 0; i < n; i++) | ||
16 | { | ||
17 | printf("%d\n", vectorx[i]); | ||
18 | } | ||
19 | printf("Enter_element to be deleted\n"); | ||
20 | scanf("%d", &element); | ||
21 | for (i = 0; i < n; i++) | ||
22 | { | ||
23 | if (vectorx[i] == element) | ||
24 | { | ||
25 | found = 1; | ||
26 | pos = i; | ||
27 | break; | ||
28 | } | ||
29 | } | ||
30 | if (found == 1) | ||
31 | { | ||
32 | for (i = pos; i < n - 1; i++) | ||
33 | { | ||
34 | vectorx[i] = vectorx[i + 1]; | ||
35 | } | ||
36 | printf("The resultant_Vector is \n"); | ||
37 | for (i = 0; i < n - 1; i++) | ||
38 | { | ||
39 | printf("%d\n", vectorx[i]); | ||
40 | } | ||
41 | } | ||
42 | else | ||
43 | printf("Element %d is not found in the vector\n", element); | ||
44 | } |
Enter number of Elements: 5
120
216
578
269
Input Array Elements are:
120
216
269
579
Enter Element deleted"
216
The resultant Vector is:
120
269
579