Add to Favorites    Make Home Page 2438 Online  
 Language Categories  
 Our Services  

Home » C Home » Beginners / Lab Assignments Home » Simulation of Banking Algorithm (Mini Project)

A D V E R T I S E M E N T

Search Projects & Source Codes:

Title Simulation of Banking Algorithm (Mini Project)
Author HEMAMALINI.R
Author Email jasmine_hm4021 [at] yahoo.co.in
Description
Category C » Beginners / Lab Assignments
Hits 388933
Code Select and Copy the Code
Code : #include<stdio.h> struct process { int max[10],allocate[10],need[10],nallocate[10],nneed[10]; int finish; }p[10]; int avail[10],navail[10],req[10]; int i,j,m,n,sum,s,pno; int generate(); void newstatus(); void main() { int k,l; printf(" ENTER THE TOTAL NUMBER OF RESOURCES : "); scanf("%d",&n); printf(" ENTER THE NUMBER OF AVAILABLE UNITS IN EACH RESOURCE TYPE : "); for(i=0;i<n;i++) scanf("%d",&avail[i]); printf(" ENTER THE TOTAL NUMBER OF PROCESSES : "); scanf("%d",&m); printf(" ENTER THE MAXIMUM NUMBER OF UNITS NEEDED IN "); printf(" EACH RESOURCE TYPE FOR EACH PROCESS: "); for(i=0;i<m;i++) for(j=0;j<n;j++) scanf("%d",&p[i].max[j]); printf(" ENTER THE ALLOCATED NUMBER OF UNITS IN "); printf(" EACH RESOURCE TYPE FOR EACH PROCESS: "); for(i=0;i<m;i++) for(j=0;j<n;j++) { scanf("%d",&p[i].allocate[j]); p[i].need[j]=p[i].max[j]-p[i].allocate[j]; } for(j=0;j<n;j++) { sum=0; for(i=0;i<m;i++) sum+=p[i].allocate[j]; avail[j]=avail[j]-sum; } newstatus(); printf(" THE NEED MATRIX IS: "); for(i=0;i<n;i++) printf("R%d ",i+1); for(i=0;i<m;i++) { printf(" "); for(j=0;j<n;j++) printf("%d ",p[i].need[j]); } l=generate(); if(l==0) printf(" THE SYSTEM IS NOT IN THE SAFE STATE!!! "); else { newstatus(); printf(" ENTER THE PROCESS NUMBER AND ITS REQUEST: "); scanf("%d",&pno); pno=pno-1; k=s=0; for(i=0;i<n;i++) { scanf("%d",&req[i]); if((req[i]>avail[i])||(req[i]>p[pno].need[i])) k=1; if(req[i]!=p[pno].need[i]) s=1; } if(k==1) printf(" THE REQUEST CANNOT BE GRANTED!!! "); else if(k==0) { for(i=0;i<n;i++) { p[pno].nneed[i]=(p[pno].nneed[i])-req[i]; p[pno].nallocate[i]=(p[pno].nallocate[i])+req[i]; navail[i]=navail[i]-req[i]; if(s==0) navail[i]=navail[i]+p[pno].nallocate[i]; } printf(" "); if(s==0) { printf(" P%d ",pno+1); p[pno-1].finish=1; } l=generate(); if(l==0) printf(" THE REQUEST CANNOT BE GRANTED!!! "); if(l==1) printf(" THE REQUEST IS GRANTED!!! "); } } } void newstatus() { for(i=0;i<n;i++) navail[i]=avail[i]; for(i=0;i<m;i++) { for(j=0;j<n;j++) { p[i].nallocate[j]=p[i].allocate[j]; p[i].nneed[j]=p[i].need[j]; } p[i].finish=0; } } int generate() { int l,q,k,f; l=0; while(1) { for(i=0;i<m;i++) { if(p[i].finish==0) { k=1; for(j=0;j<n;j++) if(p[i].nneed[j]>navail[j]) k=0; if(k==0) l++; else if(k==1) { printf("P%d ",i+1); for(j=0;j<n;j++) navail[j]+=p[i].nallocate[j]; p[i].finish=1; } } } if(l>m) return 0; q=0; for(f=0;f<m;f++) if(p[f].finish==1) q++; if(q==m) { printf(" ABOVE IS THE SAFE SEQUENCE AND THE SYSTEM IS IN SAFE STATE!!! "); return 1; } } }

Related Source Codes

Script Name Author
The Game Opposite as seen on Nokia 2300 Mobile Manikanta
RECURSIVE BALANCED QUICK SORT ashish
Radix Sort ashish
Change your mouse pointer Ashim
The blinking star Shashank
Data Validation Crylittlebaby
To search a file by giving file type like mp3 or mpeg or doc Prashanth SR
Menus Demonstration B.Chidhambaram
Employee Database Project Using C. Reenku Raman Nayak
Creating a Lexical Analyzer in c fahad bader al-buhairi �դ ?�� ��??���
Calendar Program Omkar & Devendra
Stop double Process for start in C Cedrik Jurak
Stop double Process for start in C Cedrik Jurak
Time Scheduler Atiq Anwar
A timepass game between atmost two players Rahul Roy

A D V E R T I S E M E N T




Google Groups Subscribe to SourceCodesWorld - Techies Talk
Email:

Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

New! Click here to Add your Code!


ASP Home | C Home | C++ Home | COBOL Home | Java Home | Pascal Home
Source Codes Home Page

 Advertisements  

Google Search

Google

Source Codes World.com is a part of Vyom Network.

Vyom Network : Web Hosting | Dedicated Server | Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

Sitemap | Privacy Policy | Terms and Conditions | Important Websites
Copyright ©2003-2024 SourceCodesWorld.com, All Rights Reserved.
Page URL: http://www.sourcecodesworld.com/source/show.asp?ScriptID=919


Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions | Quick2Host Review