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

Программа на C ++ для вычисления коэффициента распределения прибыли

Дана массив, состоящий из инвестиций нескольких людей, другой массив содержит соответствующие временные интервалы инвестиций валюты, задача - сгенерировать коэффициент распределения прибыли.

What is the profit sharing ratio

In a partnership, partners should distribute profits and losses according to the capital invested by the partners in the enterprise. According to 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-partner 1 = investment funds * time period    

 partner 2 = investment funds * time period     

partner 3 = investment funds * time period       

partner 4 = investment funds * time cycle...      

person n = investment capital * time period 

profit sharing ratio = partner 1 : partner 2 : partner 3

Пример

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

  • input as an array of capital invested by multiple partners, as well as another array of 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)
   Конец
   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]
   Конец
   declare int ratio = GCD(arr, size)
   Loop For i = 0 and i < size - 1 and i++
      вывод arr[i] / ratio
   Конец
   вывод arr[i] / ratio
Шаг 3-> В main() объявить int amount[] = { 1000, 2000, 2000 }
   заявление int time[] = { 2, 3, 4 }
   расчет int size = sizeof(amount) / sizeof(amount[0])
   вызов cal_ratio(amount, time, size)
Стоп

Пример

#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);
  возврат result;
}
//calculate profit sharing ratio
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 << "коэффициент разделения прибыли ";
    cal_ratio(amount, time, size);
    возврат 0;
}

результат вывода

коэффициент разделения прибыли 1 : 3 : 4
Основной учебник
Вам может понравиться