# Author: Alagappan Karthikeyan

## Simulate Bankers Algorithm for Deadlock Avoidance Using C

void main(){int n,r,i,j,k,p,u=0,s=0,m;int block[10],run[10],active[10],newreq[10];int max[10][10],resalloc[10][10],resreq[10][10];int totalloc[10],totext[10],simalloc[10];//clrscr();printf(“Enter the no of processes:”);scanf(“%d”,&n);printf(“Enter the no ofresource classes:”);scanf(“%d”,&r);printf(“Enter the total existed resource in each class:”);for(k=1; k<=r; k++)scanf(“%d”,&totext[k]);printf(“Enter the allocated resources:”);for(i=1; i<=n; i++)for(k=1; k<=r; k++)scanf(“%d”,&resalloc);printf(“Enter the process making the new request:”);scanf(“%d”,&p);printf(“Enter the requested resource:”);for(k=1; k<=r; k++)scanf(“%d”,&newreq[k]);printf(“Enter the process which are n blocked or running:”);for(i=1; i<=n; i++){if(i!=p){printf(“process %d:\n”,i+1);scanf(“%d%d”,&block[i],&run[i]);}}block[p]=0;run[p]=0;for(k=1; k<=r; k++){ }OUTPUT:Enter …

## C Program to Simulate PRIORITY CPU Scheduling Algorithm

void main(){int et[20],at[10],n,i,j,temp,p[10],st[10],ft[10],wt[10],ta[10];int totwt=0,totta=0;float awt,ata;char pn[10][10],t[10];//clrscr();printf(“Enter the number of process:”);scanf(“%d”,&n);for(i=0; i<n; i++){printf(“Enter process name,arrivaltime,execution time & priority:”);//flushall();scanf(“%s%d%d%d”,pn[i],&at[i],&et[i],&p[i]);}for(i=0; i<n; i++)for(j=0; j<n; j++){if(p[i]<p[j]){temp=p[i];p[i]=p[j];p[j]=temp;temp=at[i];at[i]=at[j];at[j]=temp;temp=et[i];et[i]=et[j];et[j]=temp;strcpy(t,pn[i]);strcpy(pn[i],pn[j]);strcpy(pn[j],t);}}for(i=0; i<n; i++) }OUTPUT: Enter the number of process:3Enter process name,arrivaltime,execution time & priority:1 2 1 3Enter process name,arrivaltime,execution time & priority:3 5 4 1Enter process name,arrivaltime,execution time & priority:3 4 6 2 Pname arrivaltime …

Start reading C Program to Simulate PRIORITY CPU Scheduling Algorithm

## Bubble Sort in C

Bubble sort is a beginners sorting program, it is most learned, but not most used widely due to its time complexity. Bubble sort time complexity is O(n2) Code for Bubble Sort in C include int main(){int a[10],i,j,temp,n;printf(“\n Enter the max no.of Elements to Sort: \n”);scanf(“%d”,&n);printf(“\n Enter the Elements : \n”);for(i=0; ia[j]){temp=a[i];a[i]=a[j];a[j]=temp;}}for(i=0; i<n; i++){printf(“%d\t”,a[i]);}return 0;} Output for …

Start reading Bubble Sort in C

## C Program to Calculate Sum of Marks to Demonstrate Structures

include struct student{char name[10];int rollno;int subject[5],total;};main ( ){static struct student s[100];int n,i,j;//clrscr();printf(“Enter the number of Students: “);scanf(“%d”,&n);printf(“Enter the Marks of Five Subjects: “);for(i=0; i<n; i++){printf(“\nEnter student[%d] student marks”,i);s[i].total=0;for(j=0; j<5; j++){scanf(“%d”,&s[i].subject[j]);s[i].total=s[i].total+s[i].subject[j];}printf(“%d\n”,s[i].total);}}OUTPUT:Enter the number of Students: 2Enter the Marks of Five Subjects:Enter student[0] student marks 95 95 95 95 95475 Enter student[1] student marks96 96 96 96 …

Start reading C Program to Calculate Sum of Marks to Demonstrate Structures

## C Program Example to Initialize Structure Variable

include struct student{char name[50];int roll;float marks;};void main(){struct student s;printf(“Enter information of students:\n\n”);printf(“Enter name: “);scanf(“%s”,s.name);printf(“Enter Roll Number: “);scanf(“%d”,&s.roll);printf(“Enter Marks: “);scanf(“%f”,&s.marks);printf(“\nPrinting Entered Data: \n”);printf(” Name: %s\n Roll Number: %d\n Marks: %.2f\n”,s.name,s.roll,s.marks);getch();}OUTPUT: Enter information of students: Enter name: LuckyEnter Roll Number: 538Enter Marks: 98 Printing Entered Data:Name: LuckyRoll Number: 538Marks: 98.00

Start reading C Program Example to Initialize Structure Variable

## C Program to Find Roots of a Quadratic Equation

include include include main(){float a,b,c,d,x1,x2;int ch;//clrscr();printf(“Enter a,b,c values”);scanf(“%f%f%f”,&a,&b,&c);d=pow(b,2)-4ac;if(d==0)ch=1;else if(d>0){ch=2;}elsech=3;printf(“A=%6.2f\nB=%6.2f\nC=%6.2f\n”,a,b,c);printf(“Discriminate D=%6.2f\n”,d);switch(ch){case 1:printf(“Equal Roots”);x1=x2=-b/(2a); printf(“x1=x2=%6.2f\n”,x1); break; case 2: printf(“Roots are Real and inequal”); x1=(-b+sqrt(d))/(2a);x2=(-b-sqrt(d))/(2a); printf(“x1=%6.2f\n”,x1); printf(“x2=%6.2f\n”,x2); break; case 3: printf(“Imaginary roots \n”); printf(“x1=%6.2f+i%6.2f\n”,-b/(2a), sqrt(-d)/(2a)); printf(“x2=%6.2f-i%6.2f\n”,-b/(2a), sqrt(-d)/(2*a));break;}getch();}OUTPUT: Enter a,b,c values10 20 30A= 10.00B= 20.00C= 30.00Discriminate D=-800.00Imaginary rootsx1= -1.00+i 1.41×2= -1.00-i 1.41