Can you fix any mistake on this C program
Question
Can you fix any mistake on this C program:
#include <studio.h> #include <conio.h> #include <stdlib.h> void fcfsAlgorithm() { point f("#first come first serve algorithm\n") float burst-time[30], waiting-time[30], turnaround-time[30]; float average-waiting-time= 0.0, average turn.turnaround.time = 0.0) int count. j, total process; Point f ("***\n") Point f ("Enter the amount of processes to execute: "); Scan f ("%d", & total-process); Point f ("\n Enter the burst time of processes: \n\n"); for (count = 0; count < total-process; count++) { Point f("Process [%d]:", count + 1); Scan f ("%f", & burst-time[count]); } waiting_time[0] = 0; for (count = 1; count = total-process; count++) { waiting time [count]= 0; for (j=0; j<count; j++) { waiting_time[count]= waiting-time[count] + burst time [j]; }} Point f ("-----\n"); Point f ("\n Process/t/t Burst Time /t Waiting Time /n"); Point f ("-----\n); for (count 0; count < total process; count++) { turnaround-time[count] = burst-time (count) + waiting-time/c}; average-waiting-time = average-waiting-time+ waiting-time [count]; Point f("\n Process[%d] | t% 2f\t\t%, 2f", count+1, burst-time[count], waiting time [count], turnaround-time[count] } Point f ("\n ----- \n"); waiting time (0) = 0; for (i = 1; i , limit; i++) { waiting-time [i] = 0; for (j=0, j < i; j++) { waiting-time [i]+ burst-time [j]; } sum=sum+waiting-time[i]; } average-wait-time= (float) sum/limit; sum = 0; Point f("-----\n"); Point f("In process ID\t\t Burst time \t Waiting Time \n"); Point f("-----\n"); for (i=o, i<time, i++) { Point f ("\n Process [d%] \t\t%d\t\t%d\n", Process [i], turnaround-time[13]; } Point f(\n Average Waiting Time: %f\n", average-wait-time); Point f(\n Average turnaround Time: %f\n", average-turnaround-time); }
Summary
Initially, the logic in this program is all correct but there are many errors in this program. Every time where it is the need of printf function it is instead written as pointf. Variables can consist of number, alphabets and underscore. But here instead of the underscore Hyphen symbol is used. Also in many places instead of the semicolon braces are used. Bracketing can also be seen not done properly. Also many variables are not declared but used.
Explanation
Firstly there is a first come first serve algorithm is used. Where three arrays are declared for the burst time, turn around time and Waiting time. Input function is used to take the input from the user and it will take input as the number of processes. Also for each process user will also enter the burst time. After that for each process waiting time and turn around time is calculated. Later there is table of the process number, burst time, waiting time, turn-around time will get printed on the screen. Finally the average of the turn around time and waiting time is printed on the screen.
Code
#include <stdio.h> #include <conio.h> #include <stdlib.h> void fcfsAlgorithm() { printf("first come first serve algorithm\n"); float burst_time[30], waiting_time[30], turnaround_time[30]; float average_waiting_time= 0.0; float average_turnaround_time=0.0; int count,j, total_process; printf("***\n"); printf("Enter the amount of processes to execute: "); scanf("%d", & total_process); printf("\n Enter the burst time of processes: \n\n"); for(count = 0; count < total_process; count++) { printf("Process [%d]:", count + 1); scanf("%f", & burst_time[count]); } waiting_time[0] = 0; for (count = 1; count<total_process; count++) { waiting_time [count]= 0; for (j=0; j<count; j++) { waiting_time[count]= waiting_time[count] + burst_time [j]; } } printf("-----\n"); printf("\n Process\t Burst Time \t Waiting Time \tTurn-around time\n"); printf("-----\n"); for(count=0; count < total_process; count++) { turnaround_time[count] = burst_time[count] + waiting_time[count]; average_waiting_time = average_waiting_time+ waiting_time[count]; average_turnaround_time=average_turnaround_time+turnaround_time[count]; printf("\n Process[%d]\t\t%.2f\t\t%.2f\t\t%.2f", count+1, burst_time[count], waiting_time[count], turnaround_time[count]); } printf("\n"); printf("----------"); printf("\n"); average_waiting_time= average_waiting_time/total_process; average_turnaround_time=average_turnaround_time/total_process; printf("\n Average Waiting Time: %f\n", average_waiting_time); printf("\n Average turnaround Time: %f\n", average_turnaround_time); } int main() { fcfsAlgorithm(); }
Output
Also read, implement a task finding the root of a function f(x). You are to implement the Bisection method.