Posts

Showing posts with the label C

Linked File Allocation

Image
Write a C Program to implement Linked File Allocation method. #include<stdio.h> #include<conio.h> #include<stdlib.h> void main() { int f[50], p,i, st, len, j, c, k, a; clrscr(); for(i=0;i<50;i++) f[i]=0; printf("Enter how many blocks already allocated: "); scanf("%d",&p); printf("Enter blocks already allocated: "); for(i=0;i<p;i++) {  scanf("%d",&a);  f[a]=1; } x: printf("Enter index starting block and length: "); scanf("%d%d", &st,&len); k=len; if(f[st]==0) {  for(j=st;j<(st+k);j++)  {  if(f[j]==0)  {  f[j]=1;  printf("%d-------->%d\n",j,f[j]);  }  else  {  printf("%d Block is already allocated \n",j);  k++;  }  } } else printf("%d starting block is already allocated \n",st); printf("Do you want to enter more file(Yes - 1/No - 0)"); scanf("%d", &c); if(c==1)  goto x; else  exit(0); ...

Indexed File Allocation method

Image
Write a C Program to implement Indexed File Allocation method #include<stdio.h> #include<conio.h> #include<stdlib.h> void main() { int f[50], index[50],i, n, st, len, j, c, k, ind,count=0; clrscr(); for(i=0;i<50;i++) f[i]=0; x:printf("Enter the index block: "); scanf("%d",&ind); if(f[ind]!=1) {  printf("Enter no of blocks needed and no of files for the index %d on the disk : \n", ind);  scanf("%d",&n); } else {  printf("%d index is already allocated \n",ind);  goto x; } y: count=0; for(i=0;i<n;i++) {  scanf("%d", &index[i]);  if(f[index[i]]==0)  count++; } if(count==n) {  for(j=0;j<n;j++)  f[index[j]]=1;  printf("Allocated\n");  printf("File Indexed\n");  for(k=0;k<n;k++)  printf("%d-------->%d : %d\n",ind,index[k],f[index[k]]); } else { printf("File in the index is already allocated \n"); printf(...

Sequential File Allocation

Image
Write a C Program to implement Sequential File Allocation method #include < stdio.h> #include<conio.h> void main() { int f[50], i, st, len, j, c, k, count = 0; clrscr(); for(i=0;i<50;i++) f[i]=0; printf("Files Allocated are : \n"); x: count=0; printf(“Enter starting block and length of files: ”); scanf("%d%d", &st,&len); for(k=st;k<(st+len);k++)  if(f[k]==0)  count++; if(len==count) {  for(j=st;j<(st+len);j++)  if(f[j]==0)  {  f[j]=1;  printf("%d\t%d\n",j,f[j]);  }  if(j!=(st+len-1))  printf(” The file is allocated to disk\n"); } else printf(” The file is not allocated \n"); printf("Do you want to enter more file(Yes - 1/No - 0)"); scanf("%d", &c); if(c==1)  goto x; else  exit(); getch(); } Output:

Priority Scheduling

Image
Write a C program to implement the various process scheduling mechanisms such as Priority Scheduling. #include<stdio.h> #include<conio.h> void main() {  int i,j,n,bt[10],p[10],compt[10], wt[10],tat[10],temp1,temp2;  float sumwt=0.0,sumtat=0.0,avgwt,avgtat;  clrscr();  printf("Enter number of processes: ");  scanf("%d",&n);  printf("Enter the burst time of %d process\n", n);  for(i=0;i<n;i++)  scanf("%d",&bt[i]);  printf("Enter the priority of %d process\n", n);  for(i=0;i<n;i++)  scanf("%d",&p[i]);  for(i=0;i<n;i++)  for(j=i+1;j<n;j++)  if(p[i]>p[j]) {  temp1=bt[i];  bt[i]=bt[j];  bt[j]=temp1;  temp2=p[i];  p[i]=p[j];  p[j]=temp2; }  compt[0]=bt[0]; wt[0]=0;  for(i=1;i<n;i++)  compt[i]=bt[i]+compt[i-1];  for(i=0;i<n;i++)  {  tat[i]=compt[i];  wt[i]=tat[i]-bt[i];  sumtat...

First-come, first-serve scheduling(FCFS):

Image
Write a C program to implement the various process scheduling mechanisms such as   First-come, first-serve scheduling(FCFS): #include<stdio.h> #include<conio.h> #include<string.h> void main() {  int i,j,n,bt[10],compt[10],at[10], wt[10],tat[10];  float sumwt=0.0,sumtat=0.0,avgwt,avgtat;  clrscr();  printf("Enter number of processes: ");  scanf("%d",&n);  printf("Enter the burst time of %d process\n", n);  for(i=0;i<n;i++)  {  scanf("%d",&bt[i]);  }  printf("Enter the arrival time of %d process\n", n);  for(i=0;i<n;i++)  {  scanf("%d",&at[i]);  }  compt[0]=bt[0]-at[0];  for(i=1;i<n;i++)  compt[i]=bt[i]+compt[i-1];  for(i=0;i<n;i++)  {  tat[i]=compt[i]-at[i];  wt[i]=tat[i]-bt[i];  sumtat+=tat[i];  sumwt+=wt[i];  }  avgwt=sumwt/n;  avgtat=sumtat/n;  printf("---------------...

Round Robin Scheduling

Image
Write a C program to implement the various process scheduling mechanisms such as Round Robin Scheduling. #include<stdio.h> #include<conio.h> struct process {  char pn[10];  int bt,ct,time; }p[10]; void main() {  int i,full,n,tq,wt[10],tat[10], time1=0;  float avgwt=0.0;  clrscr();  printf("Enter number of processes:");  scanf("%d",&n);  printf("Enter process name and burst time of %d process\n", n);  for(i=0;i<n;i++)  {  scanf("%s%d",&p[i].pn,&p[i].bt);  p[i].time=p[i].bt;  }  printf("Enter quantum:");  scanf("%d",&tq);  full=n;  while(full)  {  for(i=0;i<n;i++)  {  if(p[i].bt>=tq)  {  p[i].bt-=tq; time1=time1+tq;  }  else if(p[i].bt!=0)  {  time1+=p[i].bt;  p[i].bt=0;  }  else  continue;  if(p[i].bt==0)  {  full=full-1;  tat[i]=time1...

Index Sequential and Interpolation Search

Image
Write a Program to implement Searching methods Index Sequential and Interpolation Search using menu driven programming. #include<stdio.h> #include<conio.h> int interpolation_search(int a[],int i,int j,int key); int index_sequential(int a[],int n,int key); void main() {  int a[30],key,mid,p,q,k,n,i,result,op;  clrscr();  do  {   printf("\n1) Interpolation Search\n2) Index Sequential Search\n3) Quit\n");   printf("Enter your choice: ");   scanf("%d",&op);   switch(op)   {    case 1:printf("\n Enter No. of Element: ");              scanf("%d",&n);              printf("\n Enter a sorted list of %d elements : ",n);             for(i=0;i<n;i++)             scanf("%d",&a[i]);             printf("\n Enter the element to searched : "...

Binary search tree

Image
Write a Program to implement a binary search tree.                            #include<stdio.h> #include<conio.h> #include<stdlib.h> struct node {  int data;  struct node *left;  struct node *right; }; struct node *tree; struct node *insertElement(struct node *,int); void preorderTraversal(struct node*); void inorderTraversal(struct node *); void postorderTraversal(struct node*); void main() { int option,val; struct node *ptr; clrscr(); do { printf("\n*****************MAIN MENU****************\n"); printf("\n1.Insert Element"); printf("\n2.Preorder traversal"); printf("\n3.Inodere Traversal"); printf("\n4.Postorder Traversal"); printf("\n\n***********************************************"); printf("\n\nEnter Your Option"); scanf("%d",&option); switch(opt...

Double ended queue

Image
Write a Program to implement double ended queue menu driven program. #include<stdio.h> #include<conio.h> #include<stdlib.h> #define MAX 10 int deque[MAX]; int left=-1, right=-1; void input_deque(void); void output_deque(void); void insert_left(void); void insert_right(void); void delete_left(void); void delete_right(void); void display(void); void main() { int option; clrscr(); printf("\n 1. INPUT RESTRICTED DEQUEUE"); printf("\n 2. OUTPUT RESTRICTED DEQUEUE"); printf("\nENTER YOUR OPTION: "); scanf("%d",&option); switch(option) { case 1: input_deque(); break; case 2: output_deque(); break; } getch(); } void input_deque() { int option; do { printf("\n 1. Insert at right"); printf("\n 2. Delete from left"); printf("\n 3. Delete from right"); printf("\n 4. Display"); printf("\n 5. Quit"); printf("\n\n Enter your option: \n...

Implementation of Binary Tree

Image
Implementation of Binary Tree Menu Driven Program. #include<stdio.h> #include<conio.h> #include<stdlib.h> typedef struct node {             int data;             struct node *left, *right; }node; node *create(); void inorder(node *t); void preorder(node *t); void postorder(node *t); node *create() {             node *p;             int x;             printf("\n Enter the data (-1 for null node)");             scanf("%d",&x);             if(x==-1)             return NULL;   ...

Construction of expression tree using Postfix Expression

Image
Implementation of construction of expression tree using postfix Expression. #include<stdio.h> #include<conio.h> #include<ctype.h> #include<stdlib.h> typedef struct treenode   {             char data;              struct treenode *left;              struct treenode *right;   }treenode; typedef struct stack  {             treenode *data[20];             int top;  }stack; void init(stack *s)  {             s->top=-1;  } treenode *pop(stack *s)  {   treenode *p;   p=s->data[s->top];   s->top=s->top-1;   return(p...

Radix Sort

Image
Write a Program to implement radix sort.   #include<stdio.h>   #include<conio.h>   int largest(int arr[],int n);   void radix_sort(int arr[],int n);   void main()   {   int arr[10],i,n;   clrscr();   printf("Enter the number of elements in the array");   scanf("%d",&n);   printf("Enter the elements of the array");   for(i=0;i<n;i++)   {   printf("\n arr[%d]:",i);   scanf("%d",&arr[i]);   }   radix_sort(arr,n);   printf("The sorted array is......");   for(i=0;i<n;i++)   {   printf("%d \t",arr[i]);   }   getch();   }   int largest(int arr[],int n)   {   int large=arr[0],i;   for(i=1;i<n;i++)   {   if(arr[i]>large)   large=arr[i];   }   return large;   }   void radix_sort(int arr[],int n)   {   int...