Created
August 3, 2022 15:27
-
-
Save saharshg29/d022a824e5d12495391297e30f86a99c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| void main() | |
| { | |
| int n, m; | |
| printf("Enter the size of array 1 \n"); | |
| scanf("%i", &n); | |
| int arr[n]; | |
| int cpy[n]; // COPY OF ARRAY 1 | |
| // CREATING YOUR ARRAY | |
| printf("Enter the elements to array in assescending order \t"); | |
| for (int i = 0; i < n; i++) | |
| { | |
| scanf("%i", &arr[i]); | |
| } | |
| // PRINTING THE ORIGINAL ARRAY | |
| printf("Elements inserted by you are \t"); | |
| for (int i = 0; i < n; i++) | |
| { | |
| printf("%i ", arr[i]); | |
| cpy[n] = arr[i]; | |
| } | |
| printf("\nEnter new element to be inserted \n"); | |
| scanf("%i", &m); | |
| // INSERTING ELEMENT IN ITS POSITION IN ASSECNDING ORDER | |
| n += 1; | |
| arr[n + 1]; | |
| for (int i = n - 2; i > -1; i -= 1) | |
| { | |
| if (m < arr[i]) | |
| { | |
| arr[i + 1] = arr[i]; | |
| if (i == 0) | |
| { | |
| arr[i] = m; | |
| } | |
| } | |
| else | |
| { | |
| arr[i + 1] = m; | |
| break; | |
| } | |
| } | |
| // PRINTING THE NEW ARRAY | |
| printf("Your final array is \t"); | |
| for (int i = 0; i < n; i++) | |
| { | |
| printf("%i \t", arr[i]); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment