Saturday, 31 January 2015

Program to display the circular shift of an array at Nth position.

//Program to display the circular shift of an array at Nth position.

#include<iostream.h>
#include<conio.h>
void main()
{
 int a[5],temp,n,i,j,b;
 clrscr();
cout<<"Enter the 5 elements in array:";
      for(i=0;i<5;i++)
cin>>a[i];
cout<<"Array elements are:\n";
        for(i=0;i<5;i++)
cout<<a[i]<<" ";
cout<<"\nEnter the position from which you want to shift";
cin>>b;
i=0;j=b;
while(i<j)
{
temp=a[i];
for(i=0;i<4;i++)
a[i]=a[i+1];
a[i]=temp;
i++;
 j--;
}
cout<<"\Now array elements are \n";
for(i=0;i<=5;i++)
cout<<a[i]<<" ";
getch();
 }

No comments:

Post a Comment

Read contacts in iOS using Swift with error handling

Just copy and paste the below code Pre-step before pasting the below code Add below line in AppDelegate.swift file below import statement ...