amrendra2018

settle

Aug 19th, 2017
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.43 KB | None | 0 0
  1. /*program that will take individual expanses of 3 partner after spending for a period of time for common work
  2. and find out who will receive how much money who will pay how much money to whom...*/
  3.  
  4.  
  5. #include<stdio.h>
  6. #include<stdlib.h>
  7. int main()
  8.   {
  9.    
  10.     int a,suma=0, k,sumk=0, m,summ=0;
  11.     int arr[3],i,j,temp;
  12.     float avg;
  13.     int l=0,b[3],c[3],n=0;
  14.     float z,y;
  15.     int sumTotal;
  16.    
  17.     printf("NOTE:-ENTER 0(ZERO) ANYTIME TO STOP ENTERING INPUT\n\n");
  18.    
  19.     printf("Enter expanses of 1st person\n");
  20.    
  21.     while(scanf("%d",&a))
  22.       {
  23.        
  24.           suma=suma+a;
  25.          
  26.             if(a==0)
  27.             {
  28.                 break;
  29.             }
  30.        
  31.        
  32.       }
  33.      
  34.     printf("Enter expanses of 2nd person\n");
  35.     while(scanf("%d",&k))
  36.       {
  37.        
  38.           sumk=sumk+k;
  39.          
  40.             if(k==0)
  41.             {
  42.                 break;
  43.             }
  44.        
  45.        
  46.       }
  47.      
  48.    
  49.    
  50.    
  51.     printf("Enter expanses of 3rd person\n");
  52.     while(scanf("%d",&m))
  53.       {
  54.        
  55.           summ=summ+m;
  56.          
  57.             if(m==0)
  58.             {
  59.                 break;
  60.             }
  61.        
  62.        
  63.       }
  64.      
  65.    
  66.     sumTotal=suma+sumk+summ;
  67.     avg=(suma+sumk+summ)/3;
  68.    
  69.     printf("\n\t\t\tTotal Investment of 1st person = %d\n",suma);
  70.     printf("\t\t\tTotal Investment of 2nd person = %d\n",sumk);
  71.     printf("\t\t\tTotal Investment of 3rd person = %d\n\n\n",summ);
  72.    
  73.     printf("Their average expanses = %.2f\n\n",avg);
  74.     printf("Their Total expanses = %3d\n\n",sumTotal);
  75.    
  76.     arr[0]=suma;
  77.     arr[1]=sumk;
  78.     arr[2]=summ;
  79.    
  80.    
  81.    
  82.     for(i=1;i<3;i++)
  83.     {
  84.         for(j=i+1;j<3;j++)
  85.         {
  86.             if(arr[i]>arr[j])
  87.             {
  88.                 temp=b[i];
  89.                 b[i]=b[j];
  90.                 b[j]=temp;
  91.             }
  92.         }
  93.        
  94.     }
  95.    
  96.    
  97.     for(i=0;i<3;i++)
  98.     {
  99.         if(arr[i]<avg)
  100.         b[l++]=arr[i];  //array b stored person with investment < avg means they will have to pay
  101.     }
  102.    
  103.    
  104.     for(i=0;i<3;i++)
  105.     {
  106.         if(arr[i]>avg)
  107.         c[n++]=arr[i]; //array c stored person with investment > avg, means they will receive money respectively
  108.     }
  109.    
  110.   printf("---------------------------------------------\n");    
  111.    
  112.   for(i=0;i<l;i++)
  113.   {
  114.     z=avg-(float)b[i];
  115.     printf("Person with investment %d will PAY %.2f \n\n",b[i],z);
  116.   }  
  117.   printf("---------------------------------------------\n");  
  118.  
  119.  
  120.    for(i=0;i<n;i++)
  121.    {
  122.     y=(float)c[i]-avg;
  123.     printf("Person with investment %d will RECEIVE %.2f \n",c[i],y);
  124.    }  
  125.  
  126.   }
Add Comment
Please, Sign In to add comment