Posts

Showing posts from August, 2017

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(&quo

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+=tat[i];  sumwt+=wt[i];  }  avgwt=sumwt/n; avgtat=sumtat/n;  printf("

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("----------------------------------\n");  printf("PN\tBt\tCt\tTat\tWt\n");  pr

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;  }  }  }  for(i=0;i<n;i++)  {  p[i].ct=tat[i];  wt[i]=tat[i]-p[i].time;  }  printf("-----------

Program to find area of circle, rectangle, triangle using different methods

Image
Program: import java.util.*; class Area { double circle(int r){ return(3.14*r*r); } int rectangle(int l, int w){ return(l*w); } double triangle(int b, int h){ return(0.5*b*h); } } class MethodDemo { public static void main(String args[]) { int r,l,w,b,h; Scanner sc=new Scanner(System.in); Area a=new Area(); System.out.println(&quot;To calculate area of Circle, enter its radius&quot;); r=sc.nextInt(); System.out.println(&quot;To calculate area of Reactangle, enter its length and width&quot;); l=sc.nextInt(); w=sc.nextInt(); System.out.println(&quot;To calculate area of Triangle, enter its base and height&quot;); b=sc.nextInt(); h=sc.nextInt(); System.out.println(&quot;Area of Circle: &quot;+a.circle(r)); System.out.println(&quot;Area of Rectangle: &quot;+a.rectangle(l,w)); System.out.println(&quot;Area of Triangle: &quot;+a.triangle(b,h)); } } Output:

Program to implement sequential search algorithm

Image
Program: import java.util.*; class LinearSearch { public static void main(String args[]) { int c, n, search, array[]; Scanner in = new Scanner(System.in); System.out.println(&quot;Enter number of elements&quot;); n = in.nextInt(); array = new int[n]; System.out.println(&quot;Enter &quot; + n + &quot; integers&quot;); for (c = 0; c &lt; n; c++) array[c] = in.nextInt(); System.out.println(&quot;Enter value to find&quot;); search = in.nextInt(); for (c = 0; c &lt; n; c++) { if (array[c] == search) /* Searching element is present */ { System.out.println(search + &quot; is present at location &quot; + (c + 1) + &quot;.&quot;); break; } } if (c == n) /* Searching element is absent */ System.out.println(search + &quot; is not present in array.&quot;); } } Output:

Program to draw shape of rectangle, circle and oval with different color

Image
Program: import java.applet.Applet; import java.awt.Color; import java.awt.Graphics; /* &lt;applet code=&quot;colordraw.class&quot; HEIGHT=1000 WIDTH=1000&gt; &lt;/applet&gt; */ public class colordraw extends Applet { public void paint(Graphics g) { g.setColor(Color.green); g.drawRect(20,20,800,600); g.setColor(Color.yellow); g.drawOval(70,70,500,500); g.setColor(Color.blue); g.drawOval(120,120,50,90); } } Output:

Program to compute sum 1 to N numbers using recursion

Image
Program: import java.util.*; public class Sum { public static void main(String args[]) { System.out.print(&quot;Enter any number:&quot;); Scanner sc = new Scanner(System.in); int number = sc.nextInt(); int sum = sumN(number); System.out.println(&quot;Sum of &quot; + number + &quot; Numbers using Recursion is : &quot; + sum); } public static int sumN(int num) { int sum; if(num==1) return(1); else sum=num + sumN(num-1); return sum; } Output:

Program to add two matrix of size m*n

Image
Program: import java.util.*; class Mat { public static void main(String args[]) { int i,j,m,n; Scanner sc=new Scanner(System.in); System.out.println(&quot;enter no of rows &amp; column&quot;); m=sc.nextInt(); n=sc.nextInt(); int a[][]=new int [m][n]; int b[][]=new int [m][n]; int c[][]=new int [m][n]; System.out.println(&quot;Enter the first matrix&quot;); for(i=0;i&lt;m;i++) { for(j=0;j&lt;n;j++) { a[i][j]=sc.nextInt(); } } System.out.println(&quot;Enter the second matrix&quot;); for(i=0;i&lt;m;i++) { for(j=0;j&lt;n;j++) { b[i][j]=sc.nextInt(); } } System.out.println(&quot;first matrix is=:&quot;); for(i=0;i&lt;m;i++) { for(j=0;j&lt;n;j++) { System.out.print(&quot;\t&quot;+ a[i][j]); } System.out.println(); } System.out.println(&quot;second matrix is=:&quot;); for(i=0;i&lt;m;i++) { for(j=0;j&lt;n;j++) { System.out.print(&quot;\t&quot;+ b[i][j]); }

Program to calculate permutation and combination

Image
Program: import java.util.*; class Pattern { public static void main (String[] args) { int nCr,nPr,n,r; Scanner sc=new Scanner(System.in); System.out.println(&quot;Enter the value of n and r&quot;); n=sc.nextInt(); r=sc.nextInt(); nPr=fact(n)/fact(n-r); nCr=fact(n)/(fact(r)*fact(n-r)); System.out.println(&quot;nCr= &quot;+nCr); System.out.println(&quot;nPr= &quot;+nPr); } static int fact(int n) { int f=1; if(n==0) return 1; else { for(int i=1;i&lt;=n;i++) f=f*i; return f; } } } Output:

Program to find the multiplication table of entered number

Image
Program: import java.util.*; class Table {public static void main(String args[]) { int n; Scanner sc=new Scanner(System.in); System.out.print(&quot;Enter the number : &quot;); n=sc.nextInt(); for(int i=1;i&lt;=10;i++) { System.out.println(n+&quot;*&quot;+i+&quot;=&quot;+(i*n)); } } } Output:

Program to reverse the number & calculate the sum of its digit

Image
Program: import java.util.*; class Reverse {public static void main(String args[]) { int n,sum=0,r,rev=0; Scanner sc=new Scanner(System.in); System.out.println(&quot;Enter the number : &quot;); n=sc.nextInt(); while(n!=0) { r=n%10; sum=sum+r; rev=rev*10+r; n=n/10; } System.out.println(&quot;Reverse of the number is: &quot;+rev); System.out.println(&quot;Sum of the digits is : &quot;+sum); } } Output:

Program to simulate a menu driven calculator

Image
Program: import java.util.*; class calculator { public static void main(String args[]) { int a,b,n; Scanner sc=new Scanner(System.in); System.out.println(&quot;1. Addition&quot;); System.out.println(&quot;2. Subtraction&quot;); System.out.println(&quot;3. Multiplication&quot;); System.out.println(&quot;4. Division&quot;); System.out.println(&quot;5. Modulus&quot;); System.out.println(&quot;Enter your choice&quot;); n=sc.nextInt(); System.out.println(&quot;Enter two numbers&quot;); a=sc.nextInt(); b=sc.nextInt(); switch(n) { case 1: System.out.println(&quot;Result = &quot;+(a+b)); break; case 2: System.out.println(&quot;Result = &quot;+(a-b)); break; case 3: System.out.println(&quot;Result = &quot;+(a*b)); break; case 4: System.out.println(&quot;Result = &quot;+(a/b)); break; case 5: System.out.println(&quot;Result = &quot;+(a%b)); break; default: System.out.pr

Program to display Human face using applet

Image
PROGRAM: import java.awt.*; import java.applet.*; /* &lt;applet CODE=&quot;Face.class&quot; WIDTH=200 HEIGHT=200&gt; &lt;/applet&gt; */ public class Face extends Applet { public void paint(Graphics g) { g.drawOval(40,40,120,150); //head g.drawOval(57,75,30,20); //left eye g.drawOval(110,75,30,20); //right eye g.fillOval(68,81,10,10); //pupil (left) g.fillOval(121,81,10,10); // pupil( right) g.drawOval(85,100,30,30); //nose g.fillArc(60,125,80,40,180,180); // mouth g.drawOval(25,92,15,30); // left ear g.drawOval(160,92,15,30); // right ear } } } OUTPUT:

program to count frequency of a given Letter in a String

Image
Program: import java.util.*; import java.lang.*; class count { public static void main(String[] args) { int n,k=0,i; String str = &quot;&quot;; Scanner sc = new Scanner(System.in); System.out.println(&quot;Enter String: &quot;); str = sc.nextLine(); n = str.length(); System.out.println(&quot;Enter character whose occurences to count: &quot;); char ch=sc.next().charAt(0); char c[] = new char[n]; c = str.toCharArray(); for(i=0;i&lt;n;i++) { if(c[i]==ch) k++; } System.out.println(&quot;Total occurences = &quot;+k+&quot; times.&quot;); } Output:

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 : ");             scanf("%d",&key);             result=interpolation_search(a,0,n-1,key);             if(result==-1)  

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(option) { case 1: printf("\n Enter the value of the new node :&

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;             p=(node *) malloc(sizeof(node));             p->data=x;             printf("\n Enter the left Child of %d", x);             p->left=create();             printf("\n Enter the right Child of %d", x);             p->right=create();             return p; } void main() {             node *root=NULL, *p;             int op;             int x;             clrscr();      

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);  } void push(stack *s,treenode *p)  {   s->top=s->top+1;   s->data[s->top]=p;  } int empty(stack *s)  {             if(s->top==-1)                         return 1;             return 0;  } int full(stack *s)  {             if(s->top==19)                         return 1;             return 0;  } treenode *create(); void inorder(tr