591 - Box of Bricks

#include <stdio.h>

int main()
   {
   int number,store[102],i,totalbricks,moves_bricks,set=0,avg;
   
   while(scanf("%d", &number) && number)
         {
         totalbricks=0;
         moves_bricks=0;
         set +=1;
         for(i=0;i<number;i++)
             {
             scanf("%d", &store[i]);
             totalbricks += store[i];
             } // End of for 
         
         avg=totalbricks/number;
         for(i=0;i<number;i++)
             if(avg > store[i])
                moves_bricks +=avg-store[i];
         
         printf("Set #%d\n",set);
         printf("The minimum number of moves is %d.\n",moves_bricks);
         printf("\n");
         } // End of while
   } // End of main

Comments

Popular posts from this blog

371 - Ackermann Functions

Create many folder with one click