Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*program that will take individual expanses of 3 partner after spending for a period of time for common work
- and find out who will receive how much money who will pay how much money to whom...*/
- #include<stdio.h>
- #include<stdlib.h>
- int main()
- {
- int a,suma=0, k,sumk=0, m,summ=0;
- int arr[3],i,j,temp;
- float avg;
- int l=0,b[3],c[3],n=0;
- float z,y;
- int sumTotal;
- printf("NOTE:-ENTER 0(ZERO) ANYTIME TO STOP ENTERING INPUT\n\n");
- printf("Enter expanses of 1st person\n");
- while(scanf("%d",&a))
- {
- suma=suma+a;
- if(a==0)
- {
- break;
- }
- }
- printf("Enter expanses of 2nd person\n");
- while(scanf("%d",&k))
- {
- sumk=sumk+k;
- if(k==0)
- {
- break;
- }
- }
- printf("Enter expanses of 3rd person\n");
- while(scanf("%d",&m))
- {
- summ=summ+m;
- if(m==0)
- {
- break;
- }
- }
- sumTotal=suma+sumk+summ;
- avg=(suma+sumk+summ)/3;
- printf("\n\t\t\tTotal Investment of 1st person = %d\n",suma);
- printf("\t\t\tTotal Investment of 2nd person = %d\n",sumk);
- printf("\t\t\tTotal Investment of 3rd person = %d\n\n\n",summ);
- printf("Their average expanses = %.2f\n\n",avg);
- printf("Their Total expanses = %3d\n\n",sumTotal);
- arr[0]=suma;
- arr[1]=sumk;
- arr[2]=summ;
- for(i=1;i<3;i++)
- {
- for(j=i+1;j<3;j++)
- {
- if(arr[i]>arr[j])
- {
- temp=b[i];
- b[i]=b[j];
- b[j]=temp;
- }
- }
- }
- for(i=0;i<3;i++)
- {
- if(arr[i]<avg)
- b[l++]=arr[i]; //array b stored person with investment < avg means they will have to pay
- }
- for(i=0;i<3;i++)
- {
- if(arr[i]>avg)
- c[n++]=arr[i]; //array c stored person with investment > avg, means they will receive money respectively
- }
- printf("---------------------------------------------\n");
- for(i=0;i<l;i++)
- {
- z=avg-(float)b[i];
- printf("Person with investment %d will PAY %.2f \n\n",b[i],z);
- }
- printf("---------------------------------------------\n");
- for(i=0;i<n;i++)
- {
- y=(float)c[i]-avg;
- printf("Person with investment %d will RECEIVE %.2f \n",c[i],y);
- }
- }
Add Comment
Please, Sign In to add comment