# selfstudy: Remove all smallest integers

• 09-13-2006
tongboy
selfstudy: Remove all smallest integers
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?
• 09-13-2006
Daved
Layout ten M&Ms in front of you in a row. Start removing all the yellow ones and sliding the others over to fill in the empty spaces. Each time you remove another yellow one, notice how the sliding you are doing changes. Do the same thing with your array.

Also, don't forget to return a value from your function. What value you return will also help you figure out when to stop the deletion loop.
• 09-13-2006
Cat
First: code tags are your friend.

Second: This is the C++ forum; your program is C. Either you should convert it to C++ (which in fact would make this far, far easier to solve -- using a std::vector in place of the array makes the logic for removal trivial) or ask the mods to move the post to the correct forum.
• 09-14-2006
swgh
Code:

`void main()`
I thought many compilers would flag this as an error nowdays. Void main has long since gone.
I use
Code:

`int main ( void )`
. I think void main is non standard, but i could be wrong.
Perhaps C compilers like Miriacle C still accept it, but many standard C++ compilers wouid give at least a warning
• 09-14-2006
Salem
Miracle C isn't a C compiler.
It's a student assignment pretending to be a compiler, but since it's \$\$\$ nagware, and there are many free (and fully featured) compilers available, it makes for a very poor choice.