In: Computer Science
#include<stdio.h>
int main()
{
int size,temp,i,j,pivot,x,array[30];
printf("How many elements you want?\n");
scanf("%d",&size);
printf("Enter the pivot\n");
scanf("%d",&pivot);
printf("Enter %d arrays: ",size);
for(i=0;i<size;i++)
scanf("%d",&array[i]);
for(i=size-2;i>=0;i--){
for(j=0;j<=i;j++){
if(array[j]>array[j+1]){
temp=array[j];
array[j]=array[j+1];
array[j+1]=temp;
}
}
}
for(i=0;i<size;i++)
{
if(array[i]==pivot)
{
x=i;
}
}
printf("\nArray less than pivot is:\n");
for(i=0;i<=x;i++)
{
printf("%d ",array[i]);
}
printf("\nArray greater than pivot is:\n");
for(int i=x+1;i<=size-1;i++)
{
printf("%d ",array[i]);
}
}
The input and output of the program is also shown in picture.In this program just sort the elements of the array and then find the index of pivot in that array.Use one loop to print elements <=pivot and use another loop to print elements>pivot.
I think this is the easiest way to do this