HOME

Saturday, March 14, 2015

C PROGRAM TO INSERT VALUE IN FIXED LOCATION IN ARRAY

#include<stdio.h>
#include<conio.h>
void main()
{
    int n, a[10],value, position,i;
    printf("enter the limit\n");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        printf("enter the number\n");
        scanf("%d",&a[i]);
    }
    printf("enter the position to insert the value\n");
    scanf("%d",&position);
    printf("enter the value to insert \n");
    scanf("%d",&value);
    for(i=n;i>=position-1;i--)
    {
        a[i+1]=a[i];
    }
     a[position-1]=value;
    printf("the numbers are \n");
    for(i=0;i<=n;i++)
    {
        printf("%d\t",a[i]);
    }
}