[ create a new paste ] login | about

Link: http://codepad.org/HIWZ7OfB    [ raw code | output | fork ]

C, pasted on Oct 16:
#include <stdio.h>
#include <stdlib.h>

int  *rotate(int *a,int size,int count)
{

int *c,j,temp,k=0,sign;

c=(int *)calloc(size,sizeof(int));

sign =count>>31;

temp=(sign==-0x01)? (size-(-count)) : count;

for(j=(temp);j<size;j++)
	{
	c[k]=a[j];
		k++;
	}

	for(j=0;j<(temp);j++)
	{
	c[k]=a[j];
	k++;}

a=c;

return a;
}

int main()
{
int *b,cnt,size,i;

printf("Enter size of Array?");
scanf("%d",&size);

b=(int *)calloc(size,sizeof(int));
for(i=0;i<size;i++)
scanf("%d",&b[i]);

while(1)
{
printf("No of elements to rotate?\n\t\tPositive Value to Rotate Left \n\t\tNegative to Right  \n\t\tEnter '0' to Quit\n");
scanf("%d",&cnt);
if(cnt==0)
{
exit(0);
}
else{
cnt=cnt%size;
b=rotate(b,size,cnt);
printf("rotated array \n");
for(i=0;i<size;i++)
printf("\t%d",b[i]);
}

}
return 0;                   
}


							


Output:
1
Timeout


Create a new paste based on this one


Comments: