First_Come_First_Serve CPU Scheduling

#include<stdio.h>
#include<conio.h>
struct proc
{
    int id;
    int burst;
    int at;
};
int main()
{
    int n,i,j,total_waiting_time,waiting_time;
    printf("Enter the number of processess: ");
    scanf("%d",&n);
    struct proc p[n],temp;
    for(i=0;i<n;i++)
    {
        p[i].id=i;
        printf("Enter the arrival time of the process: ");
        scanf("%d",&p[i].at);
        printf("Enter the burst time of the process: ");
        scanf("%d",&p[i].burst);
    }
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(p[j].at<p[i].at)
            {
                temp.id=p[j].id;
                temp.at=p[j].at;
                temp.burst=p[j].burst;
                
                p[j].id=p[i].id;
                p[j].burst=p[i].burst;
                p[j].at=p[i].at;
                
                p[i].id=temp.id;
                p[i].burst=temp.burst;
                p[i].at=temp.at;
            }
        }
    }
    waiting_time=0, total_waiting_time=0;
    printf("\nScheduling information \n");
    for(i=0;i<n;i++)
    {
        total_waiting_time+=waiting_time;
        printf("process id: %d  arrival time: %d  waiting time: %d\n",p[i].id,p[i].at,waiting_time);
        waiting_time+=p[i].burst;
    }
    printf("\nThe average waiting time: %1.2f: ",((float)total_waiting_time/n));
}

Comments

Popular posts from this blog

Reversing stack Method 2 !! (One Helper Stack only)

Populating Next Right Pointers in Each Node in O(1) space (without queue and level order)

Calculate factorial of large numbers !! (Using Arrays)

Multiplication of large numbers (Given in string format)

Left View of Binary Tree (Method 1 using recursion)

Check Bracket Sequence

Image Multiplication

Boundary Traversal of binary tree

BST to greater sum tree