#include #include #include #include #include #include double calculate_sharpe_ratio(double R, double Rf, double sigma) { return (R - Rf) / sigma; } int main() { double R, Rf, sigma; int best_investment = 0; double best_sharpe_ratio = -1.0; int investment_count = 1; while (scanf("%lf %lf %lf", &R, &sigma, &Rf) == 3) { int pipefd[2]; if (pipe(pipefd) == -1) { perror("pipe"); exit(1); } pid_t pid = fork(); if (pid == -1) { perror("fork"); exit(1); } if (pid == 0) { // Child process close(pipefd[0]); // Close unused read end double sharpe_ratio = calculate_sharpe_ratio(R, Rf, sigma); write(pipefd[1], &sharpe_ratio, sizeof(sharpe_ratio)); close(pipefd[1]); exit(0); } else { // Parent process close(pipefd[1]); // Close unused write end double sharpe_ratio; read(pipefd[0], &sharpe_ratio, sizeof(sharpe_ratio)); close(pipefd[0]); wait(NULL); // Wait for child to finish printf("%.2f\n", sharpe_ratio); if (sharpe_ratio > best_sharpe_ratio) { best_sharpe_ratio = sharpe_ratio; best_investment = investment_count; } investment_count++; } } printf("Selected Investment: %d\n", best_investment); return 0; } 10 5 1 7 3 1 12 8 2 finish 1.80 2.00 1.25 Selected Investment: 2