write a program to insert an element at the specified
position in the given array in c language
Answers were Sorted based on User's Feedback
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,item,n,a[10],loc,flg;
clrscr();
printf("Enter the limit N : ");
scanf("%d",&n);
if(n<=10)
{
for(i=1;i<=n;i++)
{
printf("a[%d] = ",i);
scanf("%d",&a[i]);
}
printf("\nEnter the Location = ");
scanf("%d",&loc);
for(j=1;j<=n;j++)
{
if(loc==j)
{
flg=1;
printf("Insert = ");
scanf("%d",&item);
for(i=n;i>=loc;i--)
{
a[i+1]=a[i];
}
a[loc]=item;
}
}
if(flg==1)
{
n++;
}
else
{
printf("Location not Found");
}
printf("\nNew List\n");
for(i=1;i<=n;i++)
{
printf("\n%d",a[i]);
}
}
else
{
printf("Limit is not Valid ");
}
getch();
}
Is This Answer Correct ? | 24 Yes | 5 No |
Answer / koshy
#include "stdio.h"
main()
{
char str="hello world";
char i,j,a,b,len;
len=((const char *)str);
printf("char to be inserted:");
scanf("%d",&a);
printf("at position");
scanf("%d",&b);
for(i=0;i<len;i++)
{
temp=str[b];
str[b]=a;
str[b+1]=temp;
for(j=b+1;(j<len) &&(str[j]!=0);j++)
{
str[j+1]=str[j];
}
}
}
Is This Answer Correct ? | 19 Yes | 14 No |
Answer / ajith.s uit adoor(2008-2010)
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,item,n,a[10],u,k;clrscr();
printf("enter the limit\n");
scanf("%d",&n);
if(n>=10)
{
printf("Array exceed limit .correct the limit value below
10 \n");
}
else
{
printf("enter the inserted element");
scanf("%d",&item);
printf("enter the position\n");
scanf("%d",&k);
if(k<=n||k<=10)
{
printf("enter the terms\n");
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
printf("inserted list\n");
for(i=1;i<=n;i++)
{
printf("%d\n",a[i]);
}
printf("inser list\n");
j=n;
while(j>=k)
{
a[j+1] =a[j];
j=j-1;
}
a[k]=item;
for(i=1;i<=n+1;i++)
{
printf("%d\n",a[i]);
}
}
else
{
printf("postion given in below limit not equal to \n");
}
}
getch();
}
Is This Answer Correct ? | 12 Yes | 12 No |
Answer / ashok kannan
Hi to all,
/* program to insert element in the array at given
position*/
#include<stdio.h>
#include<conio.h>
void main()
{
char c,t2,t1,a[100]="This is c program";
int n,i;
printf("Enter the position and the element\n");
scanf("%d%c",&n,c);
for(i=n,t1=a[i];a[i]!='\0';i++)
{
t2=a[i+1];
a[i+1]=t1;
t1=t2;
}
a[n]=c;
printf("%s",a);
getch();
}
Is This Answer Correct ? | 19 Yes | 46 No |
Answer / bhagya
#include<stdio.h>
#include<conio.h>
void main()
{
char c[20]="this is a string";
int n;
printf("en etr index value to which the element has to
be inserted");
c[n]=getchar();
printf("the string after inserted");
printf("%s",c);
getch();
}
Is This Answer Correct ? | 25 Yes | 55 No |
what is the value of b if a=5; b=++a + ++a
31 Answers Infosys, TCS, Tech Mahindra,
Why do we need arrays in c?
What is an lvalue and an rvalue?
we all know about the function overloading concept used in C++ and we all learnt abt that.... but that concept is already came in C in a very smaller propotion ... my question is IN WHICH CONCEPT THERE IS A USE OF FUNCTION OVERLOADING IS USED in C language?????????????
Differentiate between a for loop and a while loop? What are it uses?
c programs are converted into machine language with the help of a) an interpreter b) a compiler c) an operatinf system d) none of the above
Explain what is the difference between declaring a variable and defining a variable?
why java is called as a purely oops language.
What is the main differences between C and Embedded C?
What are the types of arrays in c?
WAP TO ACCEPT STRING AND COUNT A COMES N TIMES B COMES N TIMES C COMES N TIMES D COMES N TIMES AND SO ON......... AT LAST UNTIL Z COMES N TIMES...............
a character variable can at a time store a) 1 character b) 8 characters c) 254 characters d) none of the above