Code:
#include <stdio.h>
#define MAX_ARRAY_SIZE 100
int RemoveAllSmallest(int A[],int n)
{
int i;
int id_smallest=0;
int min_value=A[0];
for (i=1;i<n;i++)
{
if (A[i]<min_value)
{
min_value=A[i];
id_smallest=i;
}
}
for (i=id_smallest;i<n-1;i++)
{
A[i]=A[i+1];
}
}
void main()
{ int i;
int A[MAX_ARRAY_SIZE];
int n;
//Ask and read the number of integers.
printf("How many integers totally? (1-%d)",MAX_ARRAY_SIZE);
scanf("%d",&n);
printf("\nInput the integers.\n");
printf("(Each integers should be in the range 0-99. ");
printf("Seperate them with spaces.)\n");
//Read all integers
for (i=0;i<n;i++)
scanf("%d",&(A[i]));
//Remove all smallest numbers
n=RemoveAllSmallest(A,n);
//Display result
printf("\nAfter removing all smallest number(s):\r\n");
for (i=0;i<n;i++)
printf("%d ",A[i]);
}
------------------------------------------
I have tried the above, but it can not remove all the samllest integer, but only one. Can anyone help me to approch it?