first

Friday, 22 September 2017

Single level Directory in c

/*copy Right @ shyam reghu and shyamtr.blogspot.in */
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int i=0,j=0;
char dp[100];
struct dir
{
    char dname[100];
    char fname[100][100];
    int fcnt;
}dir;
void create()
{
    char dp[100];
    printf("Enter the file name :\t");
    scanf("%s",dp);
    printf("sss");
    for(i=0;i<dir.fcnt;i++)
    {
        printf("sss");
        if(strcmp(dp, dir.fname[i])==0)
        {
            printf("File %s already exist please enter another name\n\n\n ", dp);break;
        }
    }
    if(i==dir.fcnt)
    {
        strcpy(dir.fname[dir.fcnt],dp);
        printf("\n\nfile added to the directory successfully...\n\n\n");
    }
    dir.fcnt++;
   
}   
void delete()
{    char dp[100];
    printf("\n Enter the name of the file to delete:\t");
    scanf("%s",dp);
    for(i=0;i<dir.fcnt;i++)
    {
        if(strcmp(dp, dir.fname[i])==0)
        {
            printf("File %s is deleted \n",dp);
            strcpy(dir.fname[i],dir.fname[dir.fcnt-1]);break;
        }
    }
    if(i==dir.fcnt)
    {
        printf("File %s not found\n\n",dp);
    }
    else
    {
        dir.fcnt--;
    }
}
void search()
{
    char dp[100];
    printf("\n Enter the name of the file :\t");
    scanf("%s",dp);
    for(i=0;i<dir.fcnt;i++)
    {
        if(strcmp(dp, dir.fname[i])==0)
        {
            printf("File %s is found ", dp);break;
        }
    }
    if(i==dir.fcnt)
    {
        printf("File %s not found",dp);
    }
}
void display()
{
    if(dir.fcnt==0)
    printf("\n Directory Empty");
    else
    {
        printf("\n List of files in the file directory is :\n\t");
        for(i=0;i<dir.fcnt;i++)
        printf("\t%s\n\t",dir.fname[i]);
        printf("\n");
    }
}
void main()
{
    int ch,i=0;
    printf("\nEnter name of directory :\t ");
    scanf("%s", dir.dname);
    dir.fcnt=0;
    while(1)
    {
        printf("\n\t Enter your choice\n");
        printf("\t\t~~~~~~~~~~~~~~~~~~~~\n");
        printf("\t\t* 1. Create File  *\n");
        printf("\t\t* 2. Delete File  *\n");
        printf("\t\t* 3. Search File  *\n");
        printf("\t\t* 4. Display File *\n");
        printf("\t\t* 5. Exit         *\n");
        printf("\t\t~~~~~~~~~~~~~~~~~~~~\n");
        scanf("%d",&ch);
        switch(ch)
        {
            case 1:
                    create(); break;
            case 2:
                    delete(); break;
            case 3:
                    search(); break;
            case 4:
                    display(); break;
            case 5:
                    exit(0);
            default :
                    printf(" Wrong entry...please try again\n");
        }
    }
}

Wednesday, 20 September 2017

priority scheduling algorithm in C | non-preemptive | non-preemptive priority scheduling algorithm in c program | priority scheduling algorithm with Gantt chart in C

/*Copy Right SHYAM REGHU $$$ shyamtr.blogspot.com */#include<stdio.h>
void main()
{
 int n,i,j,TEMP,TEMP1,TEMP2,TEMP3,TEMP4;
 float WTSUM=0,TATSUM=0;
 int bt[10],at[10],P[10],ct[10],tat[10],wt[10],pt[10];
 printf("enter the no of  process\n");
 scanf("%d",&n);
 for(i=1;i<=n;i++)
 {
  printf("Enter the arrival time of p%d:\t",i);
  scanf("%d",&at[i]);
  printf("Enter burst time of p%d: \t",i);
  scanf("%d",&bt[i]);
  printf("Enter the priority :\t");
  scanf("%d",&pt[i]);
  P[i]=i;
  printf("\n");
 }
 ct[0]=0;
    if(bt[1]>=at[n])
    {
        ct[1]=bt[1]+at[1];
        tat[1]=ct[1]-at[1];
        wt[1]=tat[1]-bt[1];
  WTSUM=wt[1];
  TATSUM=tat[1];
        for(i=2;i<=n;i++)
        {
            for(j=i+1;j<=n;j++)
            {
                if(pt[j]<pt[i])
                {
                    TEMP4=pt[i];
                    pt[i]=pt[j];
                    pt[j]=TEMP4;
                    TEMP1=bt[i];
                    bt[i]=bt[j];
                    bt[j]=TEMP1;
                    TEMP2=at[i];
                    at[i]=at[j];
                    at[j]=TEMP2;
                    TEMP3=P[i];
                    P[i]=P[j];
                    P[j]=TEMP3;
                }
            }
                if(ct[i-1]<at[i])
                {
                    TEMP=at[i]-ct[i-1];
                    ct[i]=ct[i-1]+bt[i]+TEMP;
                    TEMP1=bt[i];
                }
                else
                {
                    ct[i]=ct[i-1]+bt[i];
                }
                tat[i]=ct[i]-at[i];
                wt[i]=tat[i]-bt[i];
                WTSUM=WTSUM+wt[i]+wt[1];
                TATSUM=TATSUM+tat[i]+tat[1];
       }
   }
            if(at[n]==0)
            {
            ct[0]=0;
            for(i=1;i<=n;i++)
                {
                    for(j=i+1;j<=n;j++)
                    {
                        if(pt[j]<pt[i])
                        {
                            TEMP4=pt[i];
                            pt[i]=pt[j];
                            pt[j]=TEMP4;
                          TEMP1=bt[i];
                          bt[i]=bt[j];
                          bt[j]=TEMP1;
                        TEMP2=at[i];
                        at[i]=at[j];
                        at[j]=TEMP2;
                        }
                    }
                if(ct[i-1]<at[i])
                {

                    TEMP=at[i]-ct[i-1];
                    ct[i]=ct[i-1]+bt[i]+TEMP;
                    TEMP1=bt[i];
                }
                else
                {
                    ct[i]=ct[i-1]+bt[i];
                }
            tat[i]=ct[i]-at[i];
            wt[i]=tat[i]-bt[i];
            WTSUM=WTSUM+wt[i];
           TATSUM=TATSUM+tat[i];
        }
    }
 printf("\n\n\n");
 printf("\tPROCESS\tBT\tAT\tPT\tTATshyam\tWT\n");
 for(i=1;i<=n;i++)
 {
 printf("\tP%d\t%d\t%d\t%d  \t%d\t%d\n\n",P[i],bt[i],at[i],pt[i],tat[i],wt[i]);
 }
 printf("Average_waiting_time = %f\n",WTSUM/n);
 printf("Average_turn_around_time= %f\n",TATSUM/n);
 printf("\n\n");
 printf("Gantt chart\n");
 for(i=1;i<=n;i++)
 {
  printf("\tP%d\t",P[i]);

 }
 printf("\n");
 for(i=1;i<=n;i++)
 {
 printf("\t%d\t",ct[i]);
 }
}
//shyamtr.blogspot.com KTU 

Round Robin Scheduling program in C | Round Robin scheduling Algorithm with Gantt chart c program|scheduling algorithms

/*Copy right SHYAM REGHU $$http://shyamtr.blogspot.in/*/
#include<stdio.h>
int at[100],bt[100],rt[100],temp[100];
float wait_time=0,turn_time=0;
void main()
{
 int c,j,n,time,r,flag=0,time_q,ltt,i,wt=0;
 printf("Enter no.of process:");
 scanf("%d",&n);
 r=n;
 for(c=0;c<n;c++)
 {
  printf("Enter arrival time of p%d:\t",c+1);
  scanf("%d",&at[c]);
  printf("Enter burst time of p%d: \t",c+1);
  scanf("%d",&bt[c]);
  rt[c]=bt[c];
  temp[c]=bt[c];
  printf("\n");
 }
 printf("Enter time quantum:\t");
 scanf("%d",&time_q);
 printf("\n\n\tprocess\tAT\tTAT\tWT shyam\n\n");
 for(time=0,c=0;r!=0;)
 {
  if(rt[c]<=time_q && rt[c]>0)
  {
  time=time+rt[c];
  rt[c]=0;
  flag=1;
  }
  else if (rt[c]>0)
  {
   rt[c]=rt[c]-time_q;
   time=time+time_q;
  }
  if(rt[c]==0 && flag==1)
  {
   wt=0;
   wt=time-at[c]-bt[c];
   r--;
   printf("\tP%d\t%d\t%d\t%d\n",c+1,at[c],time-at[c],wt);//http://shyamtr.blogspot.in/
   ltt=time-at[c];
   wait_time=wait_time+time-at[c]-bt[c];
   turn_time=turn_time+time-at[c];
   flag=0;
  }
  if(c==n-1)
   c=0;
  else if(at[c+1]<=time)
   c++;
  else
   c=0;
 }
 j=0;
 printf("\n\n\n"); 
 printf("Gantt Chart ");
  printf("\n\n\n"); 
 printf("\t");
 for(i=at[0];i<time;)
 {
  if(bt[j]>=time_q)
  {
   printf("P%d\t",j+1);
   i+=time_q;
   bt[j]=bt[j]-time_q;
  }
  else if(bt[j]>0)
  {
   printf("p%d\t",j+1);
   i+=bt[j];
   bt[j]=0;
  }
  j++;
  if(j>=n)
  {
   j=0;
  }
 }
printf("\n");

j=0;
 printf("\t");
for(i=at[0];i<time;)
 {
  if(temp[j]>=time_q)
  {
   printf("%d\t",i+time_q);
   i+=time_q;
   temp[j]=temp[j]-time_q;
  }
  else if(temp[j]>0)
  {
   printf("%d\t",i+temp[j]);
   i+=temp[j];
   temp[j]=0;
  }
  j++;
  if(j>=n)
  {
   j=0;
  }
 }

  printf("\n\n\n"); 
 printf("\nAverage_waiting_time=%f\n",wait_time/n);
 printf("Average_turn_around_time=%f\n",turn_time/n);
 printf("\n\n");
}
/*http://shyamtr.blogspot.in/*/

Wednesday, 6 September 2017

shortest job first (SJF) also known as | Shortest job next (SJN) or | shortest process next (SPN) scheduling algorithm | c program error free|

#include<stdio.h>
#define S 20
void main()
{
int bt[S],at[S],sum_bt=0,smallest,n,i,j,wt[S],ct[S],p[S],w=-1;
  int sum_turnaround=0,sum_wait=0;
float awt,att;
  printf("Enter no of processes : ");
  scanf("%d",&n);
  for(i=0;i<n;i++)
  {
    printf("Enter burst time and arrival time for proces P%d : ",i+1);
    scanf("%d %d",&bt[i],&at[i]);
    sum_bt+=bt[i];
  }
  printf("\n\nProcess\t|\tBT\t|\tAT\t|\tCT\t| Waiting Time|Turnaround Time\n\n");
  for(j=0;j<sum_bt;)
  {
    smallest=n-1;
    for(i=0;i<n;i++)
    {
      if(at[i]<=j && bt[i]>0 && bt[i]<bt[smallest])
        smallest=i;
    }
    if(smallest==S-1)
    {
      j++;
      continue;
    }
    printf("P[%d] \t|\t %d \t|\t%d\t|\t%d\t|\t%d\t%d\n",smallest+1,bt[smallest],at[smallest],at[smallest]+j+bt[smallest]-at[smallest],j-at[smallest],j+bt[smallest]-at[smallest]);
w++;
p[w]=smallest+1;
ct[w]=(j+bt[smallest]-at[smallest])+at[smallest];
    sum_turnaround+=j+bt[smallest]-at[smallest];
    sum_wait+=j-at[smallest];
    j+=bt[smallest];
    bt[smallest]=0;
  }
  for(i=0;i<n;i++)
  {
  printf("\tp%d",p[i]);
  }
printf("\nat[\t");
  for(i=0;i<n;i++)
  {
  printf("%d\t",ct[i]);
  /*printf("");*/
  }
awt=sum_wait*1.0/n;
att=sum_turnaround*1.0/n;
  printf("\n\n average waiting time = %f",awt);
  printf("\n\n average turnaround time = %f",att);
}

Round Robin Scheduling program in C | Round Robin scheduling Algorithm with Gantt chart c program|scheduling algorithms

/*Copy right SHYAM REGHU $$http://shyamtr.blogspot.in/*/ #include<stdio.h> int at[100],bt[100],rt[100],temp[100]; float wait_time=0,...