C Program – FCFS CPU scheduling algorithm

by Nideesh C on April 17, 2011 · 0 comments

in C Programming




#include<stdio.h>
#include<conio.h>
#include<process.h>
void main()
{
char p[10][5];
int tot=0,wt[10],i,n;
float avg=0;
clrscr();
printf("enter no of processes:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter process%d name:\n",i+1);
scanf("%s",&p[i]);
printf("enter process time");
scanf("%d",&pt[i]);
}
 
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=wt[i-1]+et[i-1];
tot=tot+wt[i];
}
avg=(float)tot/n;
printf("p_name\t P_time\t w_time\n");
for(i=0;i<n;i++)
printf("%s\t%d\t%d\n",p[i],et[i],wt[i]);
printf("total waiting time=%d\n avg waiting time=%f",tot,avg);
getch();
}

OUTPUT:
 enter no of processes: 5

enter process1 name: aaa
 enter process time: 4
 enter process2 name: bbb
 enter process time: 3
 enter process3 name: ccc
 enter process time: 2
 enter process4 name: ddd
 enter process time: 5
 enter process5 name: eee
 enter process time: 1

p_name  P_time  w_time
 aaa    4    0
 bbb    3    4
 ccc    2    7
 ddd    5    9
 eee    1    14
 total waiting time=34
 avg waiting time=6.80



Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C program – SJF CPU Scheduling Algorithm
  2. C Program – Priority CPU Scheduling Algorithm
  3. C program – Round Robin CPU Scheduling Algorithm
  4. Sample – Program to enter an integer and print its total value based on the formula ‘x – 1/3!x3 + 1/5!x5 – 1/7!x7 + 1/9!x9′.
  5. C program – Priority Scheduling

Leave a Comment

Previous post:

Next post: