Saturday, 21 January 2017

Write a program to shift array element with previous one (Left to Right) . Last element will be replace with first element ?

Q : Write a program to shift array element with previous one (Left to Right) . Last element will be replace with first element ?

Input /Output : 

Left shift array program  C Language

Solution : 


/*   *******************************
     Girfa : Student Help
     Left shift each element of array from left to right
     for more program visit: http://girfahelp.blogspot.in/p/c-language-array-programming.html
     ********************************
*/

#include<stdio.h>
#include<stdio.h>
#define MAX 5
void main()
{
     int ar[MAX],i,j,tmp;
     clrscr();
     for(i=0;i<MAX;i++)
           ar[i]=i+1;
     /* Holding last number */
     tmp=ar[MAX-1];
     for(i=MAX-1;i>=0;i--)
           ar[i]=ar[i-1];
     ar[0]=tmp;
     for(i=0;i<MAX;i++)
           printf("\t%d",ar[i]);
     getch();

}

No comments:

Post a Comment