Posts

Showing posts from November, 2024

Trash

 https://drive.google.com/file/d/1oOCGMLuMfnjgvk6YYVhDAMUDaMT4XJBl/view?usp=drivesdk

5.

 #include<stdio.h> #include<conio.h> #include<process.h> #define MAX_SIZE 4 int Q[MAX_SIZE], f = -1, r = -1; void main() { int ch,x; void QINSERT(int); void QDELETE(); void QDISPLAY(); while(1)  { clrscr(); printf("\n 1.insert \n 2.delete \n 3.display \n 4.exit \n\n enter your choice \n\n"); scanf("%d",&ch); switch(ch) { case 1: printf("\n enter the element to be inserted into the queue \n\n"); scanf("%d",&x); QINSERT(x); break; case 2: QDELETE(); break; case 3: QDISPLAY(); break; case 4: printf("\n Bye!!! See you later \n"); getch(); exit(0); default: printf("\n Invalid choice... try again \n"); } /* end of switch */  printf("\n\n press any key to continue........\n");  getch();  } /* end of while */ } /* end of main */ void QINSERT(int x) { if(r>=MAX_SIZE-1) { printf("\n queue overflow, insertion not possible \n"); return; } r++; Q[r]=x; if(f = = -1) f = 0; printf("\n ele...

4

 #include<stdio.h> #include<conio.h> #include<ctype.h> #include<process.h> #define MAX_SIZE 25 int s[MAX_SIZE],top=-1; char expr[25]; void main() { void PUSH(int); int POP(); int i=0,op1,op2,op3; clrscr(); printf("\n enter a valid postfix expression \n\n"); gets(expr); while(expr[i]!='\0') { if(isdigit(expr[i])) PUSH(expr[i]-'0'); else { op2=POP(); op1=POP(); switch(expr[i]) { case '+':op3=op1+op2; break; case '-':op3=op1-op2; break; case '*':op3=op1*op2; break; case '/':op3=op1/op2; break; default: printf("\n invalid operator %c \n",expr[i]); getch(); exit(0); } PUSH(op3); } i++; } if(top>0) printf("\n invalid input expression %s \n",expr); else printf("\n the result of the expression %s is %d \n",expr,s[top]); getch(); } void PUSH(int x) { if(top>=MAX_SIZE-1) { printf("\n stack overflow \n"); getch(); exit(0); } s[++top]=x; } int POP() { if(top==-1) { printf...

3.

 #include<stdio.h> #include<conio.h> #include<ctype.h> #include<process.h> #define MAX_SIZE 25 char s[MAX_SIZE]; int top=-1; void main() { void PUSH(char); char POP(); int PRIORITY(char); char infix[25],postfix[25]; int i=0,j=0; clrscr(); PUSH('#'); printf("\n enter a valid infix expression \n\n"); gets(infix); while(infix[i]! = '\0' ) { if(isalnum(infix[i])) postfix[j++]=infix[i]; else if(infix[i] = = '(' ) PUSH(infix[i]); else if(infix[i] = = ')' ) { while( s[top]! = '(' ) postfix[j++]=POP(); POP(); } else if( infix[i] = = '+' || infix[i] = = '-' || infix[i] = = '*' || infix[i] = = '/' ) { while(PRIORITY(s[top])>=PRIORITY(infix[i])) postfix[j++]=POP(); PUSH(infix[i]); } else {  printf("\n Illegal operator %c \n",infix[i]);  getch();  exit(0);  } i++; } while(s[top]! = '#' ) postfix[j++]=POP(); postfix[j]='\0'; printf("\n given infix expession is:...

2

 b. Solving the Towers of Hanoi problem. #include<stdio.h> #include<conio.h> int count; void main() { int n; void THANOI(int,char,char,char); clrscr(); printf("\n Enter the number of disks to be considered \n\n"); scanf("%d",&n); THANOI(n,'A','C','B'); printf("\n Total number of moves= %d \n",count); getch(); } void THANOI(int n,char start,char end,char mid) {  /* If only one disk, move it from A to C and return */ if(n = = 1)  {  printf("\n move disk %d from peg %c to peg %c\n",n,start,end);  count++;  getch();  return;  } /* move top n-1 disks from A to B using C as auxiliary */ THANOI(n-1,start,mid,end); /* move remaining disk from A to C */ printf("\n move disk %d from peg %c to peg %c\n",n,start,end); count++; getch(); /* move n-1 disk from B to C using A as auxiliary */ THANOI(n-1,mid,end,start); }

1.Push pop

 a. Push  b. Pop  c. Display  The program should print appropriate messages for stack overflow, stack underflow and stack   empty. #include<stdio.h> #include<conio.h> #include<process.h> #define MAX_SIZE 4 int s[MAX_SIZE],top=-1; void main() { void PUSH(int); void POP(); void DISPLAY(); int ch,x; while(1)  { clrscr(); printf("\n enter your choice \n\n 1.PUSH \n 2.POP \n 3.DISPLAY \n 4.EXIT \n\n"); scanf("%d",&ch); switch(ch) { case 1: printf("\n enter the element to be inserted \n"); scanf("%d",&x); PUSH(x); break; case 2: POP(); break; case 3: DISPLAY(); break; case 4: printf("\n Bye! See you next time.... \n"); getch(); exit(0); default: printf("\n Illegal choice, try again \n"); } printf("\n\n press any key to continue........\n"); getch();  } } void PUSH(int x) { if(top>=MAX_SIZE-1) printf("\n stack overflow, insertion not possible \n"); else { top++; s[top]=x; printf("...
 https://forms.gle/m65HWUV5WCTMeUJS8

Round Robin

 #include <stdio.h> main() { int i,x=-1,k[10],m=0,n,t,s=0; int a[50],temp,b[50],p[10],bur[10],bur1[10];int  wat[10],tur[10],ttur=0,twat=0,j=0; float awat,atur; printf("Enter no. of process : ");scanf("%d", &n); for(i=0; i<n; i++) { printf("Burst time for process P%d : ", (i+1));scanf("%d", &bur[i]); bur1[i] = bur[i]; } printf("Enter the time slice (in ms) : "); scanf("%d", &t); for(i=0; i<n; i++) { b[i] = bur[i] / t; if((bur[i]%t) != 0) b[i] += 1; m += b[i]; } printf("\n\t\tRound Robin Scheduling\n"); printf("\nGANTT Chart\n");for(i=0; i<m; i++) printf(" ----------------- "); printf("\n"); a[0] = 0; while(j < m) { if(x == n-1)x = 0; else x++; if(bur[x] >= t) { bur[x] -= t; a[j+1] = a[j] + t; if(b[x] == 1) { p[s] = x; k[s] = a[j+1];s++; } j++; b[x] -= 1; printf(" P%d |", x+1); } else if(bur[x] != 0) { a[j+1] = a[j] + bur[x];bur[x] = 0; if(b[x] ==...
 int a[10],n,key, i, low, high, res: int binsearch (int a[10], int key, int low, int high); printf("\n\n enter the number of element to be stored in the array\n\n"); scanf("%d", &n); printf("\n\n enter the array element\n\n"); scanf("%d",&n); printf("\n\n enter the array element\n\n"); for(i=0;i<n;i++) scanf("%d",&n); printf("\n\n enter the element to be searched\n\n"); scanf("%d", &key); res-binsearch (a, key, low, high); if (res==-1) printf("\n\n element &d is not found \n\n", key, res+1); getch (); int binsearch (int a[10], int key, int low, int high)

Priority

 #include <stdio.h> struct process { int pid; int btime;int pri; int wtime;int ttime; } p[10], temp; main() { int i,j,k,n,ttur,twat;float awat,atur; printf("Enter no. of process : ");scanf("%d", &n); for(i=0; i<n; i++) { printf("Burst time for process P%d (in ms) : ", (i+1));scanf("%d", &p[i].btime); printf("Priority for process P%d : ", (i+1));scanf("%d", &p[i].pri); p[i].pid = i+1; } for(i=0; i<n-1; i++) { for(j=i+1; j<n; j++) { if((p[i].pri > p[j].pri) || (p[i].pri == p[j].pri && p[i].pid > p[j].pid) ) { temp = p[i]; p[i] = p[j]; p[j] =temp; } } } p[0].wtime = 0; for(i=0; i<n; i++) { p[i+1].wtime = p[i].wtime + p[i].btime;p[i].ttime = p[i].wtime + p[i].btime; } ttur = twat = 0; for(i=0; i<n; i++) { ttur += p[i].ttime;twat += p[i].wtime; } awat = (float)twat / n;atur = (float)ttur / n; printf("\n\t Priority Scheduling\n\n");for(i=0; i<38; i++) printf("-");...

SJF

 #include <stdio.h> struct process { int pid; int btime;int wtime;int ttime; } p[10], temp; main() { int i,j,k,n,ttur,twat;float awat,atur; printf("Enter no. of process : ");scanf("%d", &n); for(i=0; i<n; i++) { printf("Burst time for process P%d (in ms) : ",(i+1));scanf("%d", &p[i].btime); p[i].pid = i+1; } for(i=0; i<n-1; i++) { for(j=i+1; j<n; j++) { if((p[i].btime > p[j].btime) || (p[i].btime == p[j].btime && p[i].pid > p[j].pid)) { temp = p[i]; p[i] = p[j]; p[j] = temp; }} } p[0].wtime = 0; for(i=0; i<n; i++) { p[i+1].wtime = p[i].wtime + p[i].btime;p[i].ttime = p[i].wtime + p[i].btime; } ttur = twat = 0; for(i=0; i<n; i++) { ttur += p[i].ttime;twat += p[i].wtime; } awat = (float)twat / n;atur = (float)ttur / n; printf("\n SJF Scheduling\n\n");for(i=0; i<28; i++) printf("-"); printf("\nProcess B-Time T-Time W-Time\n");for(i=0; i<28; i++) printf("-"); for...

Fcfs

 #include <stdio.h> struct process { int pid; int btime;int wtime;int ttime; } p[10]; main() { int i,j,k,n,ttur,twat;float awat,atur; printf("Enter no. of process : ");scanf("%d", &n); for(i=0; i<n; i++) { printf("Burst time for process P%d (in ms) : ",(i+1));scanf("%d", &p[i].btime); p[i].pid = i+1; } p[0].wtime = 0; for(i=0; i<n; i++) { p[i+1].wtime = p[i].wtime + p[i].btime;p[i].ttime = p[i].wtime + p[i].btime; } ttur = twat = 0; for(i=0; i<n; i++) {ttur += p[i].ttime;twat += p[i].wtime; } awat = (float)twat / n;atur = (float)ttur / n; printf("\n FCFS Scheduling\n\n");for(i=0; i<28; i++) printf("-"); printf("\nProcess B-Time T-Time W-Time\n");for(i=0; i<28; i++) printf("-"); for(i=0; i<n; i++) printf("\n P%d\t%4d\t%3d\t%2d", p[i].pid,p[i].btime,p[i].ttime,p[i].wtime); printf("\n"); for(i=0; i<28; i++) printf("-"); printf("\n\nAverage w...