I done with my logic which is actually used to copy a Array elements into another Array but in the final output(Point 1) of printing statement is not working well as I expecting.
#include <stdio.h>
int main()
{
int arr[50],n,key,loc;
printf("Enter size of the Elements:\n");
scanf("%d", &n);
printf("Enter %d Elements\n", n);
for(int i=0;i<n;i++)
{
scanf("%d", &arr[i]);
}
//int a = arr[i];
printf("Enter the Element to insert:\n");
scanf("%d", &key);
printf("Enter the Location to insert:\n");
scanf("%d", &loc);
for(int i=n-1;i>=loc;i--)
{
arr[i+1] = arr[i];
}
arr[loc] = key;
printf("Result of Array:\n");
for(int i=0;i<=n;i++) //Point 1
{
printf("%d\n", arr[i]);
}
return 0;
}
Its expecting to print the copied value to print but its not showing the last element of the array.
eg: a[] = 1,2,3 b[] = 8,9
Expecting o/p: 1,2,3,8,9
Actual o/p: 1,2,3,8