How to insert an element in an array at any point. And then print the updated array
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
/******************************************************* * MYCPLUS Sample Code - https://www.mycplus.com * * * * This code is made available as a service to our * * visitors and is provided strictly for the * * purpose of illustration. * * * * Please direct all inquiries to saqib at mycplus.com * *******************************************************/ //Muhammad Saqib //Please change BGI directory accouding to your TC Directory //By default it is "E:\tc\bgi" #include<stdio.h> #include<conio.h> #include<iostream.h> void main() { int a[10]; int i,n,j,item,m; clrscr(); textmode(3); printf("Enter an array of Ten Elements\n"); for ( i=1;i<=10;i++) scanf("%d",&a[i]); printf("The array you enterd was\n"); for (i=1;i<=10;i++) printf("\n%d",a[i]); printf("\nEnter Element an element to insert in the array\n"); scanf("%d",&item); printf("\nEnter Location (1--10) to insert this element\n"); scanf("%d",&m); a[m]=item; //for (i=1;i<=10;i++); printf("\nThe number was\n%d ",item); printf("\nLocation was\n%d ",m); printf("\nUpdated array is\n"); for (i=1;i<=10;i++) printf("%d\n ",a[i]); getch(); } |