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 |
There is a 100-story building and you are given two eggs. The eggs (and the building) have an interesting property that if you throw the egg from a floor number less than X, it will not break. And it will always brake if the floor number is equal or greater than X. Assuming that you can reuse the eggs which didn't broke; you got to find X in a minimal number of throws. Give an algorithm to find X in minimal number of throws.
Write a program to generate prime factors of a given integer?
declare afunction pointer to int printf(char *)?
why should i select you?
What is mean by data types in c?
write a program in c language to print your bio-data on the screen by using functions.
In c programming, explain how do you insert quote characters (? And ?) Into the output screen?
Write a program to give following output..... ********* **** **** *** *** ** ** * * ** ** *** *** **** **** *********
How can I increase the allowable number of simultaneously open files?
Write a c program to Find the name that you entered is male name or female name? Such as Sunjay is name of male and Payal is name of female
How pointers are declared?
wat is the output int main() { char s1[]="Hello"; char s2[]="Hello"; if(s1==s2) printf("Same"); else printf("Diff"); }