English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C ++Program calculates the profit distribution rate

Given an array, which consists of multiple people's investments, and another array containing the time periods for which the money was invested by the corresponding people, the task is to generate the profit sharing rate.

What is the profit sharing ratio

In a partnership, partners should distribute profits and losses according to the funds invested by the partners in the business. Based on the percentage of capital investment, we calculate the profit distribution ratio, which shows the amount of profit to be provided to each business partner.

Formula-Partner1 = invested capital*Time period    

 Partner2 = invested capital*Time period     

Partner3 = invested capital*Time period       

Partner4 = invested capital*Time cycle...      

Person n = invested capital*Time period 

Profit sharing ratio = Partner1:Partner2:Partner3

Example

Input-: amount[] = { 1000, 2000, 2000 }
   time[] = { 2, 3, 4 }
Output-: profit sharing ratio 1 : 3 : 4
Input-: amount[] = {5000, 6000, 1000}
   time[] = {6, 6, 12}
Output-: profit sharing ratio 5 : 6 :2

The method we will use to solve the given problem

  • Take the input as an array of capital investments of multiple partners, as well as another array containing the time periods for which they invested the capital

  • Multiply the capital of one partner by their corresponding time period, and then repeat with the other partner

  • Calculate the product ratio

  • Display the final result

Algorithm

Start
step 1-declare function to calculate GCD-
   int GCD(int arr[], int size)
   declare int i
   Declare int result = arr[0]
   Loop For i = 1 and i < size and i++
      set result = __gcd(arr[i], result)
   End
   return result
step 2-declare function to calculate profit sharing rate
   void cal_ratio(int amount[], int time[], int size)
   declare int i, arr[size]
   Loop For i = 0 and i < size and i++
      set arr[i] = amount[i] * time[i]
   End
   declare int ratio = GCD(arr, size)
   Loop For i = 0 and i < size - 1 and i++
      print arr[i] / ratio
   End
   print arr[i] / ratio
Step 3-> In main() declare int amount[] = { 1000, 2000, 2000 }
   declare int time[] = { 2, 3, 4 }
   calculate int size = sizeof(amount) / sizeof(amount[0])
   call cal_ratio(amount, time, size)
Stop

Example

#include <bits/stdc++.h>
using namespace std;
//Calculate GCD-
int GCD(int arr[], int size) {
    int i;
    int result = arr[0];
    for (i = 1; i < size; i++)
        result = __gcd(arr[i], result);
  return result;
}
//Calculate profit sharing rate
void cal_ratio(int amount[], int time[], int size) {
    int i, arr[size];
    for (i = 0; i < size; i++)
        arr[i] = amount[i] * time[i];
    int ratio = GCD(arr, size);
    for (i = 0; i < size - 1; i++)
        cout << arr[i] / ratio << " : ";
    cout << arr[i] / ratio;
}
int main() {
    int amount[] = { 1000, 2000, 2000 };
    int time[] = { 2, 3, 4 }
    int size = sizeof(amount) / sizeof(amount[0]);
    cout << "profit sharing ratio ";
    cal_ratio(amount, time, size);
    return 0;
}

Output result

profit sharing ratio 1 : 3 : 4