Remark: Can Anyone find error in this code......
/*c program to insert an element an array user specified loaction*/
#include <stdio.h>
#include<conio.h>
int main()
{
int ar[100],pos,c,n,val;
printf("Enter number of elements in array\n");
scanf("%d", &n);
printf("Enter %d elements\n",n);
for (c = 0; c < n; c++)
scanf("%d", &ar[c]);
printf("Enter the location where you wish to insert an element\n");
scanf("%d", &pos);
printf("Enter the value to insert\n");
scanf("%d", &val);
for (c=n-1;c>= pos-1;c--)
ar[c+1] = ar[c];
ar[pos-1]=val;
printf("array is\n");
for (c=0;c<=n;c++)
printf("%d\n",ar[c]);
getch();
return 0;
}
Output:
/*c program to insert an element an array user specified loaction*/
#include <stdio.h>
#include<conio.h>
int main()
{
int ar[100],pos,c,n,val;
printf("Enter number of elements in array\n");
scanf("%d", &n);
printf("Enter %d elements\n",n);
for (c = 0; c < n; c++)
scanf("%d", &ar[c]);
printf("Enter the location where you wish to insert an element\n");
scanf("%d", &pos);
printf("Enter the value to insert\n");
scanf("%d", &val);
for (c=n-1;c>= pos-1;c--)
ar[c+1] = ar[c];
ar[pos-1]=val;
printf("array is\n");
for (c=0;c<=n;c++)
printf("%d\n",ar[c]);
getch();
return 0;
}
Output:
Remark: Can Anyone find error in this code......
No comments:
Post a Comment
Note: only a member of this blog may post a comment.