Ad Code

Write a C program to insert the element at last

Write a C program to insert the element at last.



#include<stdio.h>
#include<conio.h>
int main()
{ clrscr();
int arr[100] = { 0 };
int i, x, pos, n;
printf("Enter the no of elements you want to enter");
scanf("%d", &n);
printf("Enter the elements");
for (i = 0; i < n; i++)
scanf("%d",&arr[i]);
arr[i] = i + 1;
for (i = 0; i < n; i++)
printf("%d ", arr[i]);
printf("\n");
printf("Enter the element you want to enter");
scanf("%d",&x);
pos = n;
n++;
for (i = n; i >= pos; i--)
arr[i] = arr[i - 1];
arr[pos - 1] = x;
for (i = 0; i < n; i++)
printf("%d ", arr[i]);
printf("\n");
getch();
}

Post a Comment

0 Comments

Ad Code