Advanced programs

C program for Shortest Job Next

C program for Shortest Job Next #include<stdio.h> #include<conio.h> #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]; […]


C program for Round Robin

C program for Round Robin   #include<stdio.h> #include<conio.h> #include<iostream.h> int t,n,s,bt[10],ct[10],ta[10],w[10],lat[10],wav,taav; int allover() { for(int i=0;i<n;i++) if(ct[i]>0) 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); […]


C program for Priority Scheduling

C program for Priority Scheduling #include<stdio.h> #include<conio.h> #include<iostream.h> 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<n;i++) { printf("\nProcess no %d : ",i+1); scanf("%d %d",&pt[i],&pp[i]); p[i]=i+1; } for(i=0;i<n-1;i++) { for(int j=i+1;j<n;j++) { if(pp[i]<pp[j]) { x=pp[i]; pp[i]=pp[j]; pp[j]=x; x=pt[i]; pt[i]=pt[j]; pt[j]=x; x=p[i]; p[i]=p[j]; […]


C program for Pass-1 Assembler

C program for Pass-1 Assembler #include<iostream.h> #include<conio.h> #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")) […]


C program for Operator Precedence

C program for Operator Precedence #include<stdio.h> #include<iostream.h> #include<conio.h> #include<string.h> #include<ctype.h> 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[j-1]),c,tolower(name[j+1])); } } } } getch(); }


C program for Macro Processor

C program for Macro Processor #include<stdio.h> #include<conio.h> #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<y1;j++) scanf("%d",&a[i][j]);   #define inputb printf("Enter the value of b:"); for(i=0;i<x2;i++) for(j=0;j<y2;j++) scanf("%d",&b[i][j]);   #define addab for(i=0;i<x1;i++) { for(j=0;j<y1;j++) { […]


C program for Lexical Analyzer

C program for Lexical Analyzer #include<iostream.h> #include<conio.h> #include<stdio.h> #include<string.h> #include<stdlib.h> #include<ctype.h> 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 […]


C progrma for First Come First Serve Algorithm

C progrma for First Come First Serve Algorithm #include<stdio.h> #include<math.h> #include<conio.h> 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 […]