Created
November 9, 2023 11:27
-
-
Save jokereven/647785392e3891cc0a8bfa7683f0a981 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
typedef struct { | |
char name[11]; | |
int priority; | |
int runtime; | |
} Process; | |
float calculate_average_turnaround_time(Process processes[], int num_processes) { | |
int current_time = 0; | |
int total_turnaround_time = 0; | |
for (int i = 0; i < num_processes; i++) { | |
int start_time = current_time; | |
current_time += processes[i].runtime; | |
int end_time = current_time; | |
int turnaround_time = end_time - start_time; | |
total_turnaround_time += turnaround_time; | |
} | |
float average_turnaround_time = (float)total_turnaround_time / num_processes; | |
return average_turnaround_time; | |
} | |
int main() { | |
Process processes[3]; | |
// 输入进程信息 | |
for (int i = 0; i < 3; i++) { | |
scanf("%s %d %d", processes[i].name, &processes[i].priority, &processes[i].runtime); | |
} | |
// 计算平均作业周转时间 | |
float average_turnaround_time = calculate_average_turnaround_time(processes, 3); | |
// 输出结果 | |
printf("%.1f\n", average_turnaround_time); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment