SlideShare uma empresa Scribd logo
1 de 35
MANAV RACHNA
UNIVERSITY
OS LAB
SAGAR AGGARWAL
B-TECH CSE -4A
2K18CSUN01080
1. To swap two numbers without using a temporary variable.
2. To calculate the bill amount for an item given the quantity sold, rate, discount and tax.
3. Program to enter any character. If the entered character is in lower case then convert it into uppercase and if it is
lower case then convert it into upper case.
4. To enter a character and determine whether it is vowel or not.
5. Program to display a menu that offers five options: Read three numbers, calculate total, average, display the
smallest and largest value.
7. To find the Fibonacci using recursive function.
8. To insert a number at a given location in an array.
10. Accept any two strings from the user. Display whether both the strings are equal or not.(do not use standard
functions).
11. Write a program to accept a list of 10 integers in an array, pass the starting address of array in sum function,
calculate the sum of the array elements in the function and return the sum calculated in the main function.
12. Program to add two numbers using Command Line Arguments
LAB 2-3
Q1
Q2
Q3
LAB 5-7
Q1
FCFS
OUTPUT
Q2 SJF
OUTPUT
Q3 SRTF
OUTPUT
Q4 ROUND ROBIN
OUTPUT
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY
Lab-9
Laboratory Objective: To implement scheduling algorithms in C.
Learning Outcome: Implementation of scheduling algorithms.
1. Implement Priority Scheduling algorithm for three process having the following Burst Time and
Priorities:
Process Burst Time Priority
1 5 2
2 7 1
3 6 3
4 5 4
OUTPUT
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY
Lab-10
Laboratory Objective: To implement scheduling algorithms.
Learning Outcome: Implementation of scheduling algorithms.
2. Implement Producer Consumer Problem using Semaphore:
OUTPUT
OS LAB 11
1- FIRST FIT
#include<stdio.h>
void main()
{
int bsize[10],psize[10],bno, pno,flags[10], allocation[10], i, j;
for(i = 0; i < 10; i++)
{
flags[i]= 0;
allocation[i]= -1;
}
printf("Enterno.of blocks: ");
scanf("%d",&bno);
printf("nEntersize ofeach block: ");
for(i = 0; i < bno; i++)
scanf("%d",&bsize[i]);
printf("nEnterno. ofprocesses:");
scanf("%d",&pno);
printf("nEntersize ofeach process: ");
for(i = 0; i < pno; i++)
scanf("%d",&psize[i]);
for(i = 0; i < pno; i++) //allocation as per first fit
for(j= 0; j < bno; j++)
if(flags[j]== 0 && bsize[j]>= psize[i])
{
allocation[j]= i;
flags[j]= 1;
break;
}
//display allocationdetails
printf("nBlockno.tsizettprocessno.ttsize");
for(i = 0; i < bno; i++)
{
printf("n%dtt%dtt",i+1, bsize[i]);
if(flags[i]== 1)
printf("%dttt%d",allocation[i]+1,psize[allocation[i]]);
else
printf("Notallocated");
}
}
OUTPUT
2- BEST FIT
#include<stdio.h>
void main()
{
int fragment[20],b[20],p[20],i,j,nb,np,temp,lowest=9999;
static int barray[20],parray[20];
printf("ntttMemory Management Scheme - Best Fit");
printf("nEnter the number of blocks:");
scanf("%d",&nb);
printf("Enter the number of processes:");
scanf("%d",&np);
printf("nEnter the size of the blocks:-n");
for(i=1;i<=nb;i++)
{
printf("Block no.%d:",i);
scanf("%d",&b[i]);
}
printf("nEnter the size of the processes :-n");
for(i=1;i<=np;i++)
{
printf("Process no.%d:",i);
scanf("%d",&p[i]);
}
for(i=1;i<=np;i++)
{
for(j=1;j<=nb;j++)
{
if(barray[j]!=1)
{
temp=b[j]-p[i];
if(temp>=0)
if(lowest>temp)
{
parray[i]=j;
lowest=temp;
}
}
}
fragment[i]=lowest;
barray[parray[i]]=1;
lowest=10000;
}
printf("nProcess_notProcess_sizetBlock_notBlock_sizetFragment");
for(i=1;i<=np && parray[i]!=0;i++)
printf("n%dtt%dtt%dtt%dtt%d",i,p[i],parray[i],b[parray[i]],fragment[i]);
}
OUTPUT
3- WORST FIT
#include<stdio.h>
int main()
{
int fragments[10], blocks[10], files[10];
int m, n, number_of_blocks, number_of_files, temp, top = 0;
static int block_arr[10], file_arr[10];
printf("nEnter the Total Number of Blocks:t");
scanf("%d",&number_of_blocks);
printf("Enter the Total Number of Files:t");
scanf("%d",&number_of_files);
printf("nEnter the Size of the Blocks:n");
for(m = 0; m < number_of_blocks; m++)
{
printf("Block No.[%d]:t", m + 1);
scanf("%d", &blocks[m]);
}
printf("Enter the Size of the Files:n");
for(m = 0; m < number_of_files; m++)
{
printf("File No.[%d]:t", m + 1);
scanf("%d", &files[m]);
}
for(m = 0; m < number_of_files; m++)
{
for(n = 0; n < number_of_blocks; n++)
{
if(block_arr[n] != 1)
{
temp = blocks[n] - files[m];
if(temp >= 0)
{
if(top < temp)
{
file_arr[m] = n;
top = temp;
}
}
}
fragments[m] = top;
block_arr[file_arr[m]] = 1;
top = 0;
}
}
printf("nFile NumbertFile SizetBlock NumbertBlock SizetFragment");
for(m = 0; m < number_of_files; m++)
{
printf("n%dtt%dtt%dtt%dtt%d", m, files[m], file_arr[m], blocks[file_arr[m]],
fragments[m]);
}
printf("n");
return 0;
}
OUTPUT
OS LAB 12
OPTIMAL PAGE REPLACEMENT ALGO
#include<stdio.h>
int main()
{
int no_of_frames, no_of_pages, frames[10], pages[30], temp[10], flag1, flag2, flag3, i, j, k,
pos, max, faults = 0;
printf("Enter number of frames: ");
scanf("%d", &no_of_frames);
printf("Enter number of pages: ");
scanf("%d", &no_of_pages);
printf("Enter page reference string: ");
for(i = 0; i < no_of_pages; ++i){
scanf("%d", &pages[i]);
}
for(i = 0; i < no_of_frames; ++i){
frames[i] = -1;
}
for(i = 0; i < no_of_pages; ++i){
flag1 = flag2 = 0;
for(j = 0; j < no_of_frames; ++j){
if(frames[j] == pages[i]){
flag1 = flag2 = 1;
break;
}
}
if(flag1 == 0){
for(j = 0; j < no_of_frames; ++j){
if(frames[j] == -1){
faults++;
frames[j] = pages[i];
flag2 = 1;
break;
}
}
}
if(flag2 == 0){
flag3 =0;
for(j = 0; j < no_of_frames; ++j){
temp[j] = -1;
for(k = i + 1; k < no_of_pages; ++k){
if(frames[j] == pages[k]){
temp[j] = k;
break;
}
}
}
for(j = 0; j < no_of_frames; ++j){
if(temp[j] == -1){
pos = j;
flag3 = 1;
break;
}
}
if(flag3 ==0){
max = temp[0];
pos = 0;
for(j = 1; j < no_of_frames; ++j){
if(temp[j] > max){
max = temp[j];
pos = j;
}
}
}
frames[pos] = pages[i];
faults++;
}
printf("n");
for(j = 0; j < no_of_frames; ++j){
printf("%dt", frames[j]);
}
}
printf("nnTotal Page Faults = %d", faults);
return 0;
}
OUTPUT
LRU PAGE REPLACEMENT ALGORITHM
#include<stdio.h>
int findLRU(int time[], int n){
int i, minimum = time[0], pos = 0;
for(i = 1; i < n; ++i){
if(time[i] < minimum){
minimum = time[i];
pos = i;
}
}
return pos;
}
int main()
{
int no_of_frames, no_of_pages, frames[10], pages[30], counter = 0, time[10], flag1, flag2, i, j,
pos, faults = 0;
printf("Enter number of frames: ");
scanf("%d", &no_of_frames);
printf("Enter number of pages: ");
scanf("%d", &no_of_pages);
printf("Enter reference string: ");
for(i = 0; i < no_of_pages; ++i){
scanf("%d", &pages[i]);
}
for(i = 0; i < no_of_frames; ++i){
frames[i] = -1;
}
for(i = 0; i < no_of_pages; ++i){
flag1 = flag2 = 0;
for(j = 0; j < no_of_frames; ++j){
if(frames[j] == pages[i]){
counter++;
time[j] = counter;
flag1 = flag2 = 1;
break;
}
}
if(flag1 == 0){
for(j = 0; j < no_of_frames; ++j){
if(frames[j] == -1){
counter++;
faults++;
frames[j] = pages[i];
time[j] = counter;
flag2 = 1;
break;
}
}
}
if(flag2 == 0){
pos = findLRU(time, no_of_frames);
counter++;
faults++;
frames[pos] = pages[i];
time[pos] = counter;
}
printf("n");
for(j = 0; j < no_of_frames; ++j){
printf("%dt", frames[j]);
}
}
printf("nnTotal Page Faults = %d", faults);
return 0;
}
OUTPUT
FIFO PAGE REPLACEMENT ALGO
#include<stdio.h>
int main()
{
int i,j,n,a[50],frame[10],no,k,avail,count=0;
printf("n ENTER THE NUMBER OF PAGES:n");
scanf("%d",&n);
printf("n ENTER THE PAGE NUMBER :n");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
printf("n ENTER THE NUMBER OF FRAMES :");
scanf("%d",&no);
for(i=0;i<no;i++)
frame[i]= -1;
j=0;
printf("tref stringt page framesn");
for(i=1;i<=n;i++)
{
printf("%dtt",a[i]);
avail=0;
for(k=0;k<no;k++)
if(frame[k]==a[i])
avail=1;
if (avail==0)
{
frame[j]=a[i];
j=(j+1)%no;
count++;
for(k=0;k<no;k++)
printf("%dt",frame[k]);
}
printf("n");
}
printf("Page Fault Is %d",count);
return 0;
}
OUTPUT

Mais conteúdo relacionado

Mais procurados

Numerical analysis
Numerical analysisNumerical analysis
Numerical analysis
Vishal Singh
 
Ds lab manual by s.k.rath
Ds lab manual by s.k.rathDs lab manual by s.k.rath
Ds lab manual by s.k.rath
SANTOSH RATH
 
Data structure new lab manual
Data structure  new lab manualData structure  new lab manual
Data structure new lab manual
SANTOSH RATH
 

Mais procurados (20)

C program
C programC program
C program
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
ADA FILE
ADA FILEADA FILE
ADA FILE
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
SPL 6.1 | Advanced problems on Operators and Math.h function in C
SPL 6.1 | Advanced problems on Operators and Math.h function in CSPL 6.1 | Advanced problems on Operators and Math.h function in C
SPL 6.1 | Advanced problems on Operators and Math.h function in C
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings
 
Data structures lab manual
Data structures lab manualData structures lab manual
Data structures lab manual
 
Data struture lab
Data struture labData struture lab
Data struture lab
 
Pnno
PnnoPnno
Pnno
 
Code optimization
Code optimization Code optimization
Code optimization
 
Numerical analysis
Numerical analysisNumerical analysis
Numerical analysis
 
Understanding storage class using nm
Understanding storage class using nmUnderstanding storage class using nm
Understanding storage class using nm
 
Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File
 
design and analysis of algorithm Lab files
design and analysis of algorithm Lab filesdesign and analysis of algorithm Lab files
design and analysis of algorithm Lab files
 
Ds lab manual by s.k.rath
Ds lab manual by s.k.rathDs lab manual by s.k.rath
Ds lab manual by s.k.rath
 
Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manual
 
BCSL 058 solved assignment
BCSL 058 solved assignmentBCSL 058 solved assignment
BCSL 058 solved assignment
 
C Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossainC Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossain
 
Data structure new lab manual
Data structure  new lab manualData structure  new lab manual
Data structure new lab manual
 

Semelhante a Operating system labs

Assignment no39
Assignment no39Assignment no39
Assignment no39
Jay Patel
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
Azhar Javed
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in c
gkgaur1987
 

Semelhante a Operating system labs (20)

Lab manual operating system [cs 502 rgpv] (usefulsearch.org) (useful search)
Lab manual operating system [cs 502 rgpv] (usefulsearch.org)  (useful search)Lab manual operating system [cs 502 rgpv] (usefulsearch.org)  (useful search)
Lab manual operating system [cs 502 rgpv] (usefulsearch.org) (useful search)
 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 Solution
 
DSC program.pdf
DSC program.pdfDSC program.pdf
DSC program.pdf
 
Os lab 1st mid
Os lab 1st midOs lab 1st mid
Os lab 1st mid
 
Os lab upto_1st_mid
Os lab upto_1st_midOs lab upto_1st_mid
Os lab upto_1st_mid
 
Os lab upto 1st mid
Os lab upto 1st midOs lab upto 1st mid
Os lab upto 1st mid
 
SaraPIC
SaraPICSaraPIC
SaraPIC
 
Code optimization
Code optimization Code optimization
Code optimization
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
 
SPL 11.1 | Problems on Loop , Nested Loop
SPL 11.1 | Problems on Loop , Nested LoopSPL 11.1 | Problems on Loop , Nested Loop
SPL 11.1 | Problems on Loop , Nested Loop
 
Assignment no39
Assignment no39Assignment no39
Assignment no39
 
C file
C fileC file
C file
 
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 
Array Cont
Array ContArray Cont
Array Cont
 
OOP program questions with answers
OOP program questions with answersOOP program questions with answers
OOP program questions with answers
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in c
 
Basic C Programming Lab Practice
Basic C Programming Lab PracticeBasic C Programming Lab Practice
Basic C Programming Lab Practice
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
 
Functions
FunctionsFunctions
Functions
 

Último

AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ankushspencer015
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Christo Ananth
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
MsecMca
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Último (20)

Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 

Operating system labs

  • 1. MANAV RACHNA UNIVERSITY OS LAB SAGAR AGGARWAL B-TECH CSE -4A 2K18CSUN01080
  • 2. 1. To swap two numbers without using a temporary variable. 2. To calculate the bill amount for an item given the quantity sold, rate, discount and tax.
  • 3. 3. Program to enter any character. If the entered character is in lower case then convert it into uppercase and if it is lower case then convert it into upper case. 4. To enter a character and determine whether it is vowel or not.
  • 4. 5. Program to display a menu that offers five options: Read three numbers, calculate total, average, display the smallest and largest value.
  • 5. 7. To find the Fibonacci using recursive function.
  • 6. 8. To insert a number at a given location in an array. 10. Accept any two strings from the user. Display whether both the strings are equal or not.(do not use standard functions).
  • 7. 11. Write a program to accept a list of 10 integers in an array, pass the starting address of array in sum function, calculate the sum of the array elements in the function and return the sum calculated in the main function.
  • 8. 12. Program to add two numbers using Command Line Arguments LAB 2-3 Q1
  • 14. OUTPUT DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY Lab-9 Laboratory Objective: To implement scheduling algorithms in C. Learning Outcome: Implementation of scheduling algorithms.
  • 15. 1. Implement Priority Scheduling algorithm for three process having the following Burst Time and Priorities: Process Burst Time Priority 1 5 2 2 7 1 3 6 3 4 5 4
  • 17. DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY Lab-10 Laboratory Objective: To implement scheduling algorithms. Learning Outcome: Implementation of scheduling algorithms. 2. Implement Producer Consumer Problem using Semaphore:
  • 18.
  • 20.
  • 21.
  • 22. OS LAB 11 1- FIRST FIT #include<stdio.h> void main() { int bsize[10],psize[10],bno, pno,flags[10], allocation[10], i, j; for(i = 0; i < 10; i++) { flags[i]= 0; allocation[i]= -1; } printf("Enterno.of blocks: "); scanf("%d",&bno); printf("nEntersize ofeach block: "); for(i = 0; i < bno; i++) scanf("%d",&bsize[i]);
  • 23. printf("nEnterno. ofprocesses:"); scanf("%d",&pno); printf("nEntersize ofeach process: "); for(i = 0; i < pno; i++) scanf("%d",&psize[i]); for(i = 0; i < pno; i++) //allocation as per first fit for(j= 0; j < bno; j++) if(flags[j]== 0 && bsize[j]>= psize[i]) { allocation[j]= i; flags[j]= 1; break; } //display allocationdetails printf("nBlockno.tsizettprocessno.ttsize"); for(i = 0; i < bno; i++) { printf("n%dtt%dtt",i+1, bsize[i]); if(flags[i]== 1) printf("%dttt%d",allocation[i]+1,psize[allocation[i]]); else printf("Notallocated"); } }
  • 25. 2- BEST FIT #include<stdio.h> void main() { int fragment[20],b[20],p[20],i,j,nb,np,temp,lowest=9999; static int barray[20],parray[20]; printf("ntttMemory Management Scheme - Best Fit"); printf("nEnter the number of blocks:"); scanf("%d",&nb); printf("Enter the number of processes:"); scanf("%d",&np); printf("nEnter the size of the blocks:-n"); for(i=1;i<=nb;i++) { printf("Block no.%d:",i); scanf("%d",&b[i]); } printf("nEnter the size of the processes :-n"); for(i=1;i<=np;i++) { printf("Process no.%d:",i); scanf("%d",&p[i]); } for(i=1;i<=np;i++) { for(j=1;j<=nb;j++) { if(barray[j]!=1) { temp=b[j]-p[i]; if(temp>=0) if(lowest>temp) { parray[i]=j; lowest=temp;
  • 27. 3- WORST FIT #include<stdio.h> int main() { int fragments[10], blocks[10], files[10]; int m, n, number_of_blocks, number_of_files, temp, top = 0; static int block_arr[10], file_arr[10]; printf("nEnter the Total Number of Blocks:t"); scanf("%d",&number_of_blocks); printf("Enter the Total Number of Files:t"); scanf("%d",&number_of_files); printf("nEnter the Size of the Blocks:n"); for(m = 0; m < number_of_blocks; m++) { printf("Block No.[%d]:t", m + 1); scanf("%d", &blocks[m]); } printf("Enter the Size of the Files:n"); for(m = 0; m < number_of_files; m++) { printf("File No.[%d]:t", m + 1); scanf("%d", &files[m]); } for(m = 0; m < number_of_files; m++) { for(n = 0; n < number_of_blocks; n++) { if(block_arr[n] != 1) { temp = blocks[n] - files[m]; if(temp >= 0) { if(top < temp) { file_arr[m] = n; top = temp; } }
  • 28. } fragments[m] = top; block_arr[file_arr[m]] = 1; top = 0; } } printf("nFile NumbertFile SizetBlock NumbertBlock SizetFragment"); for(m = 0; m < number_of_files; m++) { printf("n%dtt%dtt%dtt%dtt%d", m, files[m], file_arr[m], blocks[file_arr[m]], fragments[m]); } printf("n"); return 0; } OUTPUT
  • 29. OS LAB 12 OPTIMAL PAGE REPLACEMENT ALGO #include<stdio.h> int main() { int no_of_frames, no_of_pages, frames[10], pages[30], temp[10], flag1, flag2, flag3, i, j, k, pos, max, faults = 0; printf("Enter number of frames: "); scanf("%d", &no_of_frames); printf("Enter number of pages: "); scanf("%d", &no_of_pages); printf("Enter page reference string: "); for(i = 0; i < no_of_pages; ++i){ scanf("%d", &pages[i]); } for(i = 0; i < no_of_frames; ++i){ frames[i] = -1; } for(i = 0; i < no_of_pages; ++i){ flag1 = flag2 = 0; for(j = 0; j < no_of_frames; ++j){ if(frames[j] == pages[i]){ flag1 = flag2 = 1; break; } } if(flag1 == 0){ for(j = 0; j < no_of_frames; ++j){ if(frames[j] == -1){ faults++; frames[j] = pages[i]; flag2 = 1; break; } } }
  • 30. if(flag2 == 0){ flag3 =0; for(j = 0; j < no_of_frames; ++j){ temp[j] = -1; for(k = i + 1; k < no_of_pages; ++k){ if(frames[j] == pages[k]){ temp[j] = k; break; } } } for(j = 0; j < no_of_frames; ++j){ if(temp[j] == -1){ pos = j; flag3 = 1; break; } } if(flag3 ==0){ max = temp[0]; pos = 0; for(j = 1; j < no_of_frames; ++j){ if(temp[j] > max){ max = temp[j]; pos = j; } } } frames[pos] = pages[i]; faults++; } printf("n"); for(j = 0; j < no_of_frames; ++j){ printf("%dt", frames[j]); } } printf("nnTotal Page Faults = %d", faults); return 0;
  • 31. } OUTPUT LRU PAGE REPLACEMENT ALGORITHM #include<stdio.h>
  • 32. int findLRU(int time[], int n){ int i, minimum = time[0], pos = 0; for(i = 1; i < n; ++i){ if(time[i] < minimum){ minimum = time[i]; pos = i; } } return pos; } int main() { int no_of_frames, no_of_pages, frames[10], pages[30], counter = 0, time[10], flag1, flag2, i, j, pos, faults = 0; printf("Enter number of frames: "); scanf("%d", &no_of_frames); printf("Enter number of pages: "); scanf("%d", &no_of_pages); printf("Enter reference string: "); for(i = 0; i < no_of_pages; ++i){ scanf("%d", &pages[i]); } for(i = 0; i < no_of_frames; ++i){ frames[i] = -1; } for(i = 0; i < no_of_pages; ++i){ flag1 = flag2 = 0; for(j = 0; j < no_of_frames; ++j){ if(frames[j] == pages[i]){ counter++; time[j] = counter; flag1 = flag2 = 1; break; } } if(flag1 == 0){ for(j = 0; j < no_of_frames; ++j){ if(frames[j] == -1){ counter++; faults++; frames[j] = pages[i];
  • 33. time[j] = counter; flag2 = 1; break; } } } if(flag2 == 0){ pos = findLRU(time, no_of_frames); counter++; faults++; frames[pos] = pages[i]; time[pos] = counter; } printf("n"); for(j = 0; j < no_of_frames; ++j){ printf("%dt", frames[j]); } } printf("nnTotal Page Faults = %d", faults); return 0; } OUTPUT
  • 34. FIFO PAGE REPLACEMENT ALGO #include<stdio.h> int main() { int i,j,n,a[50],frame[10],no,k,avail,count=0; printf("n ENTER THE NUMBER OF PAGES:n"); scanf("%d",&n); printf("n ENTER THE PAGE NUMBER :n"); for(i=1;i<=n;i++) scanf("%d",&a[i]); printf("n ENTER THE NUMBER OF FRAMES :"); scanf("%d",&no); for(i=0;i<no;i++) frame[i]= -1; j=0; printf("tref stringt page framesn"); for(i=1;i<=n;i++) { printf("%dtt",a[i]); avail=0; for(k=0;k<no;k++) if(frame[k]==a[i]) avail=1; if (avail==0) { frame[j]=a[i]; j=(j+1)%no; count++;