Skip to content

Instantly share code, notes, and snippets.

@jokereven
Created November 9, 2023 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jokereven/647785392e3891cc0a8bfa7683f0a981 to your computer and use it in GitHub Desktop.
Save jokereven/647785392e3891cc0a8bfa7683f0a981 to your computer and use it in GitHub Desktop.
#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