forked from PrabhudeepSingh/C-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInsertArray.c
More file actions
40 lines (33 loc) · 761 Bytes
/
InsertArray.c
File metadata and controls
40 lines (33 loc) · 761 Bytes
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
//Program to insert element in an array
#include<stdio.h>
int main()
{
int y,i,j,n;
float a[21],x;;
printf("Enter total number of elements of you want to enter : ");
scanf("%d",&n);
while(n<=0||n>20)
{
printf("\nError... Range of elements is 0 - 20 ");
printf("\nEnter the number of elements again : ");
scanf("%d",&n);
}
printf("\n");
for(i=0;i<n;i++)
{
printf("Enter the %d element : ",i+1);
scanf("%f",&a[i]);
}
printf("\nEnter the element to be inserted : ");
scanf("%f",&x);
printf("\nEnter its element number : ");
scanf("%d",&y);
y--;
for(j=n-1;j>=y;j--)
a[j+1]=a[j];
a[y]=x;
printf("\nChanged array is : \n");
for(i=0;i<n+1;i++)
printf("Element %d : %.2f\n",i+1,a[i]);
return 0;
}