Need your opinion about this one: (currently using Turbo C v2.01)
Although someone here already pointed out the use of dynamic memory, but I dont have idea on how to use/make it.Code:#include <stdio.h> int process; main() { char choice; clrscr(); printf ("Process Scheduling\nProgrammed by: Sanchez, Anthony Ray D.\n"); printf ("\nSelect CPU Scheduling type:\n\n"); printf ("\t1. First Come, First Served (FCFS)\n"); printf ("\t2. Shortest Job First (SJF)\n"); printf ("\t3. Priority Scheduling (PS)\n"); printf ("\t4. Exit Program\n\n"); printf ("Enter your desired type: "); scanf ("%c", &choice); printf ("Enter no. of process: "); scanf ("%d", &process); switch (choice) { case '1': FCFS(); getch(); break; case '2': SJF(); getch(); break; case '3': PS(); getch(); break; case '4': clrscr(); printf ("The program has been successfully closed."); getch(); exit(); default: printf ("Invalid entry, please try again.\n"); printf ("Press any key to continue."); getch(); } } FCFS() { int ctr, PT[process]; /*I want this to have dimensions based on the value of variable "process" */ float WT=0, AWT=0; clrscr(); printf ("First Come, First Served Algorithm\n"); for (ctr=1; ctr<=process; ctr++) { printf ("Enter Processing time for P%d: ", ctr); scanf ("%d", &PT[ctr-1]); } printf ("\nProcess\t\tArrival Time\tCPU Burst\n"); for (ctr=0; ctr<=process-1; ctr++) printf ("%d\t\t%d\t\t%d\n", ctr+1, ctr, PT[ctr]); for (ctr=0; ctr<=process-1; ctr++) WT = WT + PT[ctr]; AWT = WT/process; printf ("\nAve. Waiting Time (AWT) = %.2f", AWT); return; } /* Other program lines follows... */



LinkBack URL
About LinkBacks


