Insertion is one of the operations performed on the arrays. So below is the program in C language to insert an element / item in the sorted array –
/* Program in C to insert the element in the sorted array */ #include<stdio.h> void main( ) { int a[20],n,item,i; printf("Enter the size of the array"); scanf("%d",&n); printf("Enter elements of the array in the sorted order"); for(i=0; i<n; i++) { scanf("%d", &a[i]); } printf("\nEnter ITEM to be inserted : "); scanf("%d", &item); i = n-1; while(item<a[i] && i>=0) { a[i+1] = a[i]; i--; } a[i+1] = item; n++; printf("\n\nAfter insertion array is :\n"); for(i=0; i<n; i++) { printf("\n%d", a[i]); } getch(); }
Note that the array elements to be entered in the array should be in the ascending order. As the program to made according to it. After that enter the item to be inserted and the while loop will check where the item should be inserted. It will insert the item according to the sorted ascending order.
Input –
Enter the number of elements in the array – 5
Array Elements – 5 15 25 50 52
Enter the element to be inserted – 17
Output –
Sorted array after insertion :
5 15 17 25 50 52
i want to done this programe done using dma and functions
Thanks for explaining character arrays and string arrays very well here. You can also get more insight about string arrays and character arrays here in the following location with examples.
Character arrays and string arrays in Cpp with examples
Hey man, your code is not correct, at some level of execution it will definitely crash.
Check your Condition.
your code is incorrect.
Program to insert data in a linked list in a sorted manner
Hello webmaster, i’ve been reading your site for some time and I really like coming back here.
I can see that you probably don’t make money on your page.
I know one awesome method of earning money, I think you will like it.
Search google for: dracko’s tricks
Hope you won’t mind me taking a few of the thoughts
from this article somewhere else? I guarantee full credit.
This is the first time I wanted to make a move similar to that after great stuff from https://scamfighter.net/review/essaypro.com.
Thank you and advance, and maintain your creative spirits upward!
Thanks for you.