Chapter 9 Element Shifter Write a main program that reads an integer N (that is
ID: 3698757 • Letter: C
Question
Chapter 9 Element Shifter Write a main program that reads an integer N (that is no more than 50) from standard input and then read N integers from the user input into an array. The program then passes the array to a function. This function accepts an int array and the array's size as arguments. The function creates a new array that is one element larger than the argument array. The first element of the new array should be set to 0. Element 0 of the argument array should be copied to element 1 of the new array, element 1 of the argument array should be copied to element 2 of the new array, and so forth. The function should return a pointer to the new array. After call the function, the main program prints the values of the new expanded and shifted array on standard output, one value per lineExplanation / Answer
#include <stdio.h>
void main()
{
int a[50],n,i,temp;
printf("how many numbers in array to be shifted");
scanf("%d",&n);
printf("enter the numbers");
for(i=0;i<=n;i++)
scanf("%d",a[i]);
temp= a[0];
for (i=1; i<=n-1;i++)
{
a[i-1]=a[i];
}
a[n-1]=temp;
printf("the shifted array is ");
for(i=0;i<=n-1;i++)
printf("%d "a[i]);
}
explanation:
n=size of array entered by user.
a[i] = array numbers defined.
initially temp[0] => first value in array
since we used 'for' loop defining that the old address will contain new shifted value
a[i-1]=a[i].
hence the array is shifted.