Как преобразовать этот код в псевдокод ?
#include <stdio.h> #include<curses.h> #include<string.h> int main(void){ int x; a: printf("\nPlease Enter a Number:\nEnter 1 for Non-Preemptive Shortest Job First Scheduling \nEnter 2 for Shortest Remaining Time First \nEnter 3 for Round Robin Scheduling \nEnter 4 for Priority Scheduling \nEnter 0 if you need to close the program\n"); scanf("%d", &x); if (x == 1){ int i,n,p[10]={1,2,3,4,5,6,7,8,9,10},min,k=1,btime=0; int bt[10],temp,j,at[10],wt[10],tt[10],ta=0,sum=0; float wavg=0,tavg=0,tsum=0,wsum=0; printf(" -------Shortest Job First Scheduling ( NP )-------\n"); printf("\nEnter the No. of processes :"); scanf("%d",&n); for(i=0;i<n;i++) { printf("\tEnter the burst time of %d process :",i+1); scanf(" %d",&bt[i]); printf("\tEnter the arrival time of %d process :",i+1); scanf(" %d",&at[i]); } /*Sorting According to Arrival Time*/ for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(at[i]<at[j]) { temp=p[j]; p[j]=p[i]; p[i]=temp; temp=at[j]; at[j]=at[i]; at[i]=temp; temp=bt[j]; bt[j]=bt[i]; bt[i]=temp; } } } /*Arranging the table according to Burst time, Execution time and Arrival Time Arrival time <= Execution time */ for(j=0;j<n;j++) { btime=btime+bt[j]; min=bt[k]; for(i=k;i<n;i++) { if (btime>=at[i] && bt[i]<min) { temp=p[k]; p[k]=p[i]; p[i]=temp; temp=at[k]; at[k]=at[i]; at[i]=temp; temp=bt[k]; bt[k]=bt[i]; bt[i]=temp; } } k++; } wt[0]=0; for(i=1;i<n;i++) { sum=sum+bt[i-1]; wt[i]=sum-at[i]; wsum=wsum+wt[i]; } wavg=(wsum/n); for(i=0;i<n;i++) { ta=ta+bt[i]; tt[i]=ta-at[i]; tsum=tsum+tt[i]; } tavg=(tsum/n); printf("************************"); printf("\n RESULT:-"); printf("\nProcess\t Burst\t Arrival\t Waiting\t Turn-around" ); for(i=0;i<n;i++) { printf("\n p%d\t %d\t %d\t\t %d\t\t\t%d",p[i],bt[i],at[i],wt[i],tt[i]); } printf("\n\nAVERAGE WAITING TIME : %f",wavg); printf("\nAVERAGE TURN AROUND TIME : %f",tavg); } else if (x == 2) { int n, ari[10], bur[10], total = 0, i, j, small, temp, procs[100], k, waiting[10], finish[10]; float tavg = 0.0, wavg = 0.0; printf("ENTER THE NUMBER OF PROCESSES:"); scanf("%d", & n); for (i = 0; i < n; i++) { printf("ENTER THE ARRIVAL TIME OF PROCESS %d:\t", i); scanf("%d", & ari[i]); printf("ENTER THE BURST TIME OF PROCESS %d:\t", i); scanf("%d", & bur[i]); waiting[i] = 0; total += bur[i]; } for (i = 0; i < n; i++) { for (j = i + 1; j < n; j++) { if (ari[i] > ari[j]) { temp = ari[i]; ari[i] = ari[j]; ari[j] = temp; temp = bur[i]; bur[i] = bur[j]; bur[j] = temp; } } } for (i = 0; i < total; i++){ small = 3200; for (j = 0; j < n; j++){ if ((bur[j] != 0) && (ari[j] <= i) && (bur[j] < small)){ small = bur[j]; k = j; } } bur[k]--; procs[i] = k; } k = 0; for (i = 0; i < total; i++){ for (j = 0; j < n; j++){ if (procs[i] == j){ finish[j] = i; waiting[j]++; } } } for (i = 0; i < n; i++){ printf("\n PROCESS %d:-FINISH TIME==> %d TURNAROUND TIME==>%d WAITING TIME==>%d\n", i + 1, finish[i] + 1, (finish[i] - ari[i]) + 1, (((finish[i] + 1) - waiting[i]) - ari[i])); wavg = wavg + (((finish[i] + 1) - waiting[i]) - ari[i]); tavg = tavg + ((finish[i] - ari[i]) + 1); } printf("\n AVERAGE WAITING TIME:=>\t%f\n AVERAGE TURN AROUND TIME:=>\t%f\n", (wavg / n), (tavg / n)); return 0; } else if (x == 3){ int max = 0; int i,burstTime[max],remainTime[max],remainProcess,arrivalTime[max],totalExecutionTime=0,timeQuantum,flag=0,n; float totalWaitingTime=0; printf("Enter the Number of Process(max 20) : "); scanf("%d",&n); // n is the number of Process remainProcess=n; printf("Enter Arrival Time\n"); for(i=0;i<n;i++){ printf("For P[%d]: ",i+1); scanf("%d",&arrivalTime[i]);} printf("\nEnter Burst Time\n"); for(i=0;i<n;i++){ printf("For P[%d]: ",i+1); scanf("%d",&burstTime[i]); remainTime[i]=burstTime[i]; // initially assume remain time for any process is equal to it's burst time ! } printf("\nEnter Time Quantum :"); scanf("%d",&timeQuantum); printf("\n"); for(i=0;remainProcess!=0;){ /** * this below condition check the remain time for any process is less than or equal with the time quantum * or not and also check the remain time is greater than 0 or not. if both condition are true that means * the process can execute fully at one time. */ if(remainTime[i]<=timeQuantum && remainTime[i]>0){ totalExecutionTime+=remainTime[i]; remainTime[i]=0; flag=1; } else if(remainTime[i]>0){ remainTime[i]-=timeQuantum; totalExecutionTime+=timeQuantum; } if(flag==1 && remainTime[i]==0){ printf("P[%d] | waiting Time : %d\n",i+1,totalExecutionTime-arrivalTime[i]-burstTime[i]); totalWaitingTime+=totalExecutionTime-arrivalTime[i]-burstTime[i]; flag=0; remainProcess--; } if(i==n-1) i=0; else if(arrivalTime[i+1]<=totalExecutionTime){ i++; }else i=0; } totalWaitingTime=(float)totalWaitingTime/n; printf("\nThe Average Waiting Time : %.2f \n",totalWaitingTime); } else if (x == 4){ int et[20],at[10],n,i,j,temp,p[10],st[10],ft[10],wt[10],ta[10]; int totwt=0,totta=0; float awt,ata; char pn[10][10],t[10]; //clrscr(); printf("Enter the number of process:"); scanf("%d",&n); for(i=0; i<n; i++) { printf("Enter process name,arrivaltime,execution time & priority:"); //flushall(); scanf("%s%d%d%d",pn[i],&at[i],&et[i],&p[i]); } for(i=0; i<n; i++) for(j=0; j<n; j++) { if(p[i]<p[j]) { temp=p[i]; p[i]=p[j]; p[j]=temp; temp=at[i]; at[i]=at[j]; at[j]=temp; temp=et[i]; et[i]=et[j]; et[j]=temp; strcpy(t,pn[i]); strcpy(pn[i],pn[j]); strcpy(pn[j],t); } } for(i=0; i<n; i++){ if(i==0){ st[i]=at[i]; wt[i]=st[i]-at[i]; ft[i]=st[i]+et[i]; ta[i]=ft[i]-at[i]; } else{ st[i]=ft[i-1]; wt[i]=st[i]-at[i]; ft[i]=st[i]+et[i]; ta[i]=ft[i]-at[i]; } totwt+=wt[i]; totta+=ta[i]; } awt=(float)totwt/n; ata=(float)totta/n; printf("\nPname\tarrivaltime\texecutiontime\tpriority\twaitingtime\ttatime"); for(i=0; i<n; i++) printf("\n%s\t%5d\t\t%5d\t\t%5d\t\t%5d\t\t%5d",pn[i],at[i],et[i],p[i],wt[i],ta[i]); printf("\nAverage waiting time is:%f",awt); printf("\nAverage turnaroundtime is:%f",ata); getch(); } else if (x == 0){ return 0; } else { printf("invalid input\n"); } goto a; }
Что я уже пробовал:
Как преобразовать этот код в псевдокод ?
jeron1
Вы знаете, что делает этот код?