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

C ++이익 분배율을 계산하는 프로그램

Given an array, which consists of investments by multiple individuals, and another array containing the time periods for which they invested money, 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 capital invested by the partners in the business. Based on the percentage of capital investment, we calculate the profit distribution ratio, which shows the profit amount 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:partners2:partners3

예제

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 contributions of multiple partners, as well as another array of the time periods they invested in 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++
      print arr[i] / 비율
   종료
   print arr[i] / 비율
단계 3-> 주요() 내에서 declare int amount[] = { 1000, 2000, 2000 }
   declare int time[] = { 2, 3, 4 }
   calculate int size = sizeof(amount) / sizeof(amount[0])
   cal_ratio(amount, time, size) 호출
정지

예제

#include <bits/stdc++.h>
using namespace std;
//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;
}
//이익 공유 비율 계산
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;
}

출력 결과

이익 공유 비율 1 : 3 : 4