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

C ++Das Programm berechnet den Profit-Aufteilungssatz

Given an array, which consists of investments by multiple individuals, and another array containing the time periods for which the money was invested by the corresponding individuals, 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

Beispiel

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

  • The input is an array of capital invested by multiple partners, as well as another array containing the time periods in which they invested the capital

  • Multiply the capital of one partner by its 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)
   Ende
   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]
   Schleife Für i = 0 und i < size und i++
      setzen arr[i] = amount[i] * time[i]
   Ende
   erklaren int ratio = GCD(arr, size)
   Schleife Für i = 0 und i < size - 1 und i++
      ausgeben arr[i] / ratio
   Ende
   ausgeben arr[i] / ratio
Schritt 3-> In main() erklaren int amount[] = { 1000, 2000, 2000 }
   erklaren int time[] = { 2, 3, 4 }
   berechnen int size = sizeof(amount) / sizeof(amount[0])
   call cal_ratio(amount, time, size)
Stop

Beispiel

#include <bits/stdc++.h>
using namespace std;
//GCD berechnen-
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;
}
//Berechnung der Profit-Anteilsquote
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;
}

输出结果

profit sharing ratio 1 : 3 : 4