Partitioning an array, A C program

Leave a Comment
#include<stdio.h>
#include<conio.h>
int main()
{
int a[100],b[100],c[100],n,loc,i,o,p,k=0;
printf("Enter the max limit:");
scanf("%d",&n);
for(i=0;i<n;i++) {
printf("\nEnter the element:");
scanf("%d",&a[i]);
}
printf("\nThe aray is\n\n");
for(i=0;i<n;i++) {
printf("%d\t",a[i]);
}
printf("\nEnter the element location u wanna to partition that array:");
scanf("%d",&loc);
if(loc>=n)
{
printf("\nEntered location should not be greater than or equal to the max limit!!");
getche();
exit(0);
}
o=loc;p=n-loc;loc--;
for(i=0;i {
b[i]=a[i];
}
for(i=loc;i {
c[k]=a[i];
k++;
}
printf("\nThe partitioned array are\n");
for(i=0;i<n;i++) {
printf("%d\t",b[i]);
}
printf("\n\n&\n\n");
for(i=0;i<n;i++)

{
printf("%d\t",c[i]);
}
getche();
return 0;
}

0 comments: