EmbLogic's Blog

C program to insert an element in an array of size 10

#include
int main()
{
int n,i,a[10]={1,2,3};
printf(“enter element you want to add:”);
scanf(“%d”,&n);
for(i=9;i>=0;i–)
{
a[i]=a[i-1];
if(i==0)
a[i]=n;
// printf(“a[%d]=%d\n”,i,a[i]);
}
printf(“After adding element:\n”);
for(i=0;i<9;i++)
{
printf("a[%d]=%d\n",i,a[i]);
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>