// PORGRAM FOR INSERTING VALUE IN ARRAY
#include<stdio.h>
#include<conio.h>
void main()
{
int a[20],l,t[20],pos,i,ele,count;
clrscr();
printf("enter the limit of the array:");
scantf("%d",&l);
printf("enter the array element:");
for(i=0;i<=l;i++)
scantf("%d",&a[i]);
printf("enter the position to be insert the element:");
scanf("%d",&pos);
printf("eneter the new element:");
scantf("%d",&ele);
count=pos-1;
printf("\n \n Before inserting the array element:");
for(i=0;i<=l;i++)
{
printf("%d",a[i]);
t[i]=a[i];
}
for(i=pos;i<=l;i++)//find the position
{
t[i]=a[c];
c++;
}
t[pos-1]=ele;
printf("\n After inserting the array element:\n");
for(i=0;i<=l;i++)
printf("%d",t[i]);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int a[20],l,t[20],pos,i,ele,count;
clrscr();
printf("enter the limit of the array:");
scantf("%d",&l);
printf("enter the array element:");
for(i=0;i<=l;i++)
scantf("%d",&a[i]);
printf("enter the position to be insert the element:");
scanf("%d",&pos);
printf("eneter the new element:");
scantf("%d",&ele);
count=pos-1;
printf("\n \n Before inserting the array element:");
for(i=0;i<=l;i++)
{
printf("%d",a[i]);
t[i]=a[i];
}
for(i=pos;i<=l;i++)//find the position
{
t[i]=a[c];
c++;
}
t[pos-1]=ele;
printf("\n After inserting the array element:\n");
for(i=0;i<=l;i++)
printf("%d",t[i]);
getch();
}
Errors:-
ReplyDelete1. void type is not supported in C, instead use int main(), and return 0
2. its scanf not scantf
3. and declare variable 'c' before using.
and one more, clrscr() is also not supported in Dev cpp compiler.
DeleteThis comment has been removed by the author.
Delete