3rd Year Lab Experiments-system Programming

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View 3rd Year Lab Experiments-system Programming as PDF for free.

More details

  • Words: 842
  • Pages: 14
first come first serve algorithm #include<stdio.h> #include<math.h> #include void main() { clrscr(); int p[20],b[20],w[20],t[20],i,v,n,at; int wt=0; float tw,tr; printf("enter the number of process : "); scanf("%d",&n); printf("enter cpu burst time : "); for(i=1;i<=n;i++) { scanf("%d",&b[i]); t[1]=b[1]; w[1]=0; at=t[1]; wt=w[1]; for(i=2;i<=n;i++) { t[i]=b[i]+t[i-1]; at=at+t[i]; w[i]=t[i-1]; wt=wt+w[i]; } } printf("process \t burst_time \t wait_time \t turn_around \t \n"); for(i=1;i<=n;i++) { printf("%d \t\t %d \t\t %d \t\t %d",i,b[i],w[i],t[i]); printf("\n"); } printf("\n average wait time"); tw=wt/n; printf("%f",tw); printf("\n average turn around time"); tr=at/n; printf("%f",tr); getch(); }

lexical analyzer #include #include #include<stdio.h> #include<string.h> #include<stdlib.h> #include struct pgm { char line[20]; } s[100]; void check(char s[]) { cout<<"\n"; if(!strcmpi(s,"if")) { cout<<"keyword:if"; return; } if(!strcmpi(s,"then")) { cout<<"keyword:then"; return; } if(!strcmpi(s,"else")) { cout<<"keyword:else"; return; } if(!strcmpi(s,"[end]")) { return; } cout<<"expression:"<<s; } void main() { char t[20]; int i=0,j=0,k=0; clrscr(); cout<<"\n\n enter the program code:(to stop input type end)\n"; do { gets(s[i].line);

} while(strcmpi(s[i++].line,"end")); k = k-1; do { k++; for(i=0;s[k].line[i]!='\0';i++,j++) { if(s[k].line[i]==' ') { t[j]='\0'; j=-1; check(t); } else t[j]=s[k].line[i]; } t[j]='\0'; j=0; check(t); } while(strcmpi(s[k].line,"end")); getch(); }

macro processor #include<stdio.h> #include #define getx1y1\ printf("enter the order of ist matrix:");\ scanf("%d%d",&x1,&y1); #define getx2y2\ printf("enter the order of iist matrix:");\ scanf("%d%d",&x2,&y2); #define inputa\ printf("enter the value of a:");\ for(i=0;i<x1;i++)\ for(j=0;j
printf("enter the value of b:");\ for(i=0;i<x2;i++)\ for(j=0;j
void main() { int a[5][5],b[5][5],c[5][5],i,j,k,x1,x2,y1,y2; clrscr(); getx1y1; getx2y2; if((x1==x2)&&(y1==y2)) { inputa; inputb; addab; output; } else printf("matrix addition not possible"); getch(); }

operator precedence #include<stdio.h> #include #include #include<string.h> #include void main() { int i=0,j=0,k=0,p[10]; char name[20]; char key[20]={'(',')','&','%','^','*','/','+','-','|',';'}; clrscr(); textcolor(2); cprintf("---operator precedence-----\n"); cprintf("\nenter the expression:"); scanf("%s",&name); cprintf("\n---output----\n"); for(i=0;i<20;i++) { for(j=0;j<strlen(name);j++) { char c; c=tolower(name[j]); if(!isalpha(c)&&!isdigit(c)) { if(key[i]==c) { printf("\n %c is executed %d(%c %c %c)\n",c,k++,tolower(name[j1]),c,tolower(name[j+1])); } } } } getch(); }

pass-1 assembler

#include #include #include<stdio.h> #include<stdlib.h> #include<string.h> int symi=0,lc=0,len=1,dc=0,start=0; struct pgm { char line[80]; } s[100]; struct symtab { char name[10]; int add; } sym[100]; void show(char* a,char* b,char* c) { printf("%8s %5s %6s \n",a,b,c); } void check(char s[]) { if(!strcmpi(s,"start")) { start=1; show("","start","1"); return; } if(!strcmpi(s,"end")) { show("","end","1"); return; } if(!strcmpi(s,"equ")) { show("","equ","1"); return; } if(!strcmpi(s,"ds")) { show("","ds","1"); return; } if(!strcmpi(s,"org")) { show("","org","1");

return; } if(!strcmpi(s,"dc")) { show("","dc","1"); return; } if(start) { start=0; lc=atoi(s); return; } if(dc) { dc=0; len=atoi(s); show("","ds",s); return; } for(int i=0;i<symi;i++) { if(strcmp(sym[i].name,s)==0) return; } if(s[0]=='\'') { char p[2]; sprintf(p,"lit : %s",s); show(p,"-","-"); return; } strcpy(sym[symi++].name,s); show(s,"-","-"); return; } void main() { char t[20]; int i=0,j=0,k=0; cout<<"enter the program code:"; do { gets(s[i].line); } while(strcmpi(s[i++].line,"end"));

printf("systab optab length \n"); printf("---------------------"); k=-1; do { k++; for(i=0;s[k].line[i]!='\o';i++,j++) { if(s[k].line[i]==' ') { t[j]='\o'; j=-1; check(t); } else t[j] = s[k].line[i]; } t[j]='\o'; j=0; check(t); } while(strcmpi(s[k].line,"end")); getch(); }

priority scheduling #include<stdio.h> #include #include void main() { clrscr(); int x,n,p[10],pp[10],pt[10],w[10],t[10],awt,atat,i; printf("enter the number of process : "); scanf("%d",&n); printf("\n enter process : time priorities \n"); for(i=0;i
} for(i=0;i
round robin #include<stdio.h>

#include #include int t,n,s,bt[10],ct[10],ta[10],w[10],lat[10],wav,taav; int allover() { for(int i=0;i0) return 0; return 1; } void select(int p) { w[p]+=t-lat[p]; if(ct[p]>=s) { ct[p]-=s; t+=s; } else { t+=ct[p]; ct[p]=0; } if(ct[p]==0) ta[p]=t; lat[p]=t; } void main() { int p=0;t=0;taav=0;wav=0; clrscr(); printf("enter the number of process : "); scanf("%d",&n); printf("\n enter the time slice : "); scanf("%d",&s); printf("\nenter the burst time of processes \n "); for(int i=0;i
select(p); p=(p+1)%n; } printf("\n\n process burst time wait time turn around \n\n"); for(i=0;i
shortest job next #include<stdio.h> #include #include<math.h> void main() { int s,t[20],temp,n,x[20],w[20],i,j,c,d,b[20]; float avgw,avgt; clrscr(); printf("\n enter no.of job:"); scanf("%d",&n); printf("enter the job:"); for(i=1;i<=n;i++) { scanf("%d",&b[i]); x[i]=i; } for(i=1;i<=n-1;i++) { for(j=i+1;j<=n;j++) { if(b[i]>b[j]) { temp=b[i];

b[i]=b[j]; b[j]=temp; s=x[i]; x[i]=x[j]; x[j]=s; } } } c=0; d=0; for(i=1;i<=n;i++) { w[i]=w[i-1]+b[i-1]; t[i]=b[i]+t[i-1]; w[1]=0; t[1]=b[1]; c+=w[i]; d+=t[i]; } avgw=(float)c/n; avgt=(float)d/n; printf("job \t waiting time \t service time \t turn around time \t \n :"); for(i=1;i<=n;i++) { printf("%d \t %d \t ",x[i],b[i]); printf("%d \t %d \t",w[i],t[i]); printf("\n"); } printf("average wait time %f \n",avgw); printf("average turn around %f \n",avgt); getch(); }

syntax analyzer #include<stdio.h> #include #include<string.h> #include void main()

{ int i,j,k=0,count,inc=0,n; char name[30],open[30],ch,chh,o[30]; char op[20]={'=','+','-','*','/','%','^','&','|'}; clrscr(); textcolor(3); cprintf("--syntax analyser--"); printf("\n"); printf("\n enter syntax"); printf("\n"); scanf("%s",name); n=strlen(name); for(i=0;i

Related Documents