Posts

Linked File Allocation

Image
Write a C Program to implement Linked File Allocation method. #include<stdio.h> #include<conio.h> #include<stdlib.h> void main() { int f[50], p,i, st, len, j, c, k, a; clrscr(); for(i=0;i<50;i++) f[i]=0; printf("Enter how many blocks already allocated: "); scanf("%d",&p); printf("Enter blocks already allocated: "); for(i=0;i<p;i++) {  scanf("%d",&a);  f[a]=1; } x: printf("Enter index starting block and length: "); scanf("%d%d", &st,&len); k=len; if(f[st]==0) {  for(j=st;j<(st+k);j++)  {  if(f[j]==0)  {  f[j]=1;  printf("%d-------->%d\n",j,f[j]);  }  else  {  printf("%d Block is already allocated \n",j);  k++;  }  } } else printf("%d starting block is already allocated \n",st); printf("Do you want to enter more file(Yes - 1/No - 0)"); scanf("%d", &c); if(c==1)  goto x; else  exit(0);

Indexed File Allocation method

Image
Write a C Program to implement Indexed File Allocation method #include<stdio.h> #include<conio.h> #include<stdlib.h> void main() { int f[50], index[50],i, n, st, len, j, c, k, ind,count=0; clrscr(); for(i=0;i<50;i++) f[i]=0; x:printf("Enter the index block: "); scanf("%d",&ind); if(f[ind]!=1) {  printf("Enter no of blocks needed and no of files for the index %d on the disk : \n", ind);  scanf("%d",&n); } else {  printf("%d index is already allocated \n",ind);  goto x; } y: count=0; for(i=0;i<n;i++) {  scanf("%d", &index[i]);  if(f[index[i]]==0)  count++; } if(count==n) {  for(j=0;j<n;j++)  f[index[j]]=1;  printf("Allocated\n");  printf("File Indexed\n");  for(k=0;k<n;k++)  printf("%d-------->%d : %d\n",ind,index[k],f[index[k]]); } else { printf("File in the index is already allocated \n"); printf(&quo

Sequential File Allocation

Image
Write a C Program to implement Sequential File Allocation method #include < stdio.h> #include<conio.h> void main() { int f[50], i, st, len, j, c, k, count = 0; clrscr(); for(i=0;i<50;i++) f[i]=0; printf("Files Allocated are : \n"); x: count=0; printf(“Enter starting block and length of files: ”); scanf("%d%d", &st,&len); for(k=st;k<(st+len);k++)  if(f[k]==0)  count++; if(len==count) {  for(j=st;j<(st+len);j++)  if(f[j]==0)  {  f[j]=1;  printf("%d\t%d\n",j,f[j]);  }  if(j!=(st+len-1))  printf(” The file is allocated to disk\n"); } else printf(” The file is not allocated \n"); printf("Do you want to enter more file(Yes - 1/No - 0)"); scanf("%d", &c); if(c==1)  goto x; else  exit(); getch(); } Output:

Priority Scheduling

Image
Write a C program to implement the various process scheduling mechanisms such as Priority Scheduling. #include<stdio.h> #include<conio.h> void main() {  int i,j,n,bt[10],p[10],compt[10], wt[10],tat[10],temp1,temp2;  float sumwt=0.0,sumtat=0.0,avgwt,avgtat;  clrscr();  printf("Enter number of processes: ");  scanf("%d",&n);  printf("Enter the burst time of %d process\n", n);  for(i=0;i<n;i++)  scanf("%d",&bt[i]);  printf("Enter the priority of %d process\n", n);  for(i=0;i<n;i++)  scanf("%d",&p[i]);  for(i=0;i<n;i++)  for(j=i+1;j<n;j++)  if(p[i]>p[j]) {  temp1=bt[i];  bt[i]=bt[j];  bt[j]=temp1;  temp2=p[i];  p[i]=p[j];  p[j]=temp2; }  compt[0]=bt[0]; wt[0]=0;  for(i=1;i<n;i++)  compt[i]=bt[i]+compt[i-1];  for(i=0;i<n;i++)  {  tat[i]=compt[i];  wt[i]=tat[i]-bt[i];  sumtat+=tat[i];  sumwt+=wt[i];  }  avgwt=sumwt/n; avgtat=sumtat/n;  printf("

First-come, first-serve scheduling(FCFS):

Image
Write a C program to implement the various process scheduling mechanisms such as   First-come, first-serve scheduling(FCFS): #include<stdio.h> #include<conio.h> #include<string.h> void main() {  int i,j,n,bt[10],compt[10],at[10], wt[10],tat[10];  float sumwt=0.0,sumtat=0.0,avgwt,avgtat;  clrscr();  printf("Enter number of processes: ");  scanf("%d",&n);  printf("Enter the burst time of %d process\n", n);  for(i=0;i<n;i++)  {  scanf("%d",&bt[i]);  }  printf("Enter the arrival time of %d process\n", n);  for(i=0;i<n;i++)  {  scanf("%d",&at[i]);  }  compt[0]=bt[0]-at[0];  for(i=1;i<n;i++)  compt[i]=bt[i]+compt[i-1];  for(i=0;i<n;i++)  {  tat[i]=compt[i]-at[i];  wt[i]=tat[i]-bt[i];  sumtat+=tat[i];  sumwt+=wt[i];  }  avgwt=sumwt/n;  avgtat=sumtat/n;  printf("----------------------------------\n");  printf("PN\tBt\tCt\tTat\tWt\n");  pr

Round Robin Scheduling

Image
Write a C program to implement the various process scheduling mechanisms such as Round Robin Scheduling. #include<stdio.h> #include<conio.h> struct process {  char pn[10];  int bt,ct,time; }p[10]; void main() {  int i,full,n,tq,wt[10],tat[10], time1=0;  float avgwt=0.0;  clrscr();  printf("Enter number of processes:");  scanf("%d",&n);  printf("Enter process name and burst time of %d process\n", n);  for(i=0;i<n;i++)  {  scanf("%s%d",&p[i].pn,&p[i].bt);  p[i].time=p[i].bt;  }  printf("Enter quantum:");  scanf("%d",&tq);  full=n;  while(full)  {  for(i=0;i<n;i++)  {  if(p[i].bt>=tq)  {  p[i].bt-=tq; time1=time1+tq;  }  else if(p[i].bt!=0)  {  time1+=p[i].bt;  p[i].bt=0;  }  else  continue;  if(p[i].bt==0)  {  full=full-1;  tat[i]=time1;  }  }  }  for(i=0;i<n;i++)  {  p[i].ct=tat[i];  wt[i]=tat[i]-p[i].time;  }  printf("-----------

Program to find area of circle, rectangle, triangle using different methods

Image
Program: import java.util.*; class Area { double circle(int r){ return(3.14*r*r); } int rectangle(int l, int w){ return(l*w); } double triangle(int b, int h){ return(0.5*b*h); } } class MethodDemo { public static void main(String args[]) { int r,l,w,b,h; Scanner sc=new Scanner(System.in); Area a=new Area(); System.out.println(&quot;To calculate area of Circle, enter its radius&quot;); r=sc.nextInt(); System.out.println(&quot;To calculate area of Reactangle, enter its length and width&quot;); l=sc.nextInt(); w=sc.nextInt(); System.out.println(&quot;To calculate area of Triangle, enter its base and height&quot;); b=sc.nextInt(); h=sc.nextInt(); System.out.println(&quot;Area of Circle: &quot;+a.circle(r)); System.out.println(&quot;Area of Rectangle: &quot;+a.rectangle(l,w)); System.out.println(&quot;Area of Triangle: &quot;+a.triangle(b,h)); } } Output: