Skip to main content

Posts

Showing posts from January, 2014

Email validation and separating email id from email server name in java

//file name--> Email.java import java.io.*; import java.util.*; class Email{ public static void main(String args[]) { Scanner input=new Scanner(System.in); String mail; boolean flag1=false,flag2=false; System.out.println("Enter Email Address:"); mail=input.next(); char emailid[]=mail.toCharArray(); char server[]=new char[15]; char id[]=new char[25]; int i=0,j=0; for(char temp: emailid){ if(temp=='@') flag1=true; if(flag1) { if(temp=='.') flag2=true; } if(!flag1) { id[i++]=temp; } else { if(temp!='@') server[j++]=temp; } } if(flag1 && flag2) { System.out.println("\nOutput:It is valid address."); System.out.print("Email id:"); for(char temp: id){ System.out.print(temp); } System.out.print("\nEmail server address:"); for(char temp: server){ System.out.print(temp); } }...

matrix multiplication in java

Matrix.java import java.util.*; class Matrix{ public static void main(String args[])throws Exception { Scanner s=new Scanner(System.in); int r1,r2,c1,c2; System.out.println("Enter row and column for matrix1:"); r1=s.nextInt(); c1=s.nextInt(); int[][] m1=new int[r1][c1]; System.out.println("Enter the elements of first matrix"); for(int i=0;i OUTPUT javac Matrix.java java Matrix Enter row and column for matrix1: 3 3 Enter the elements of first matrix 1 2 3 4 5 6 7 8 9 Enter row and column for matrix2: 3 3 Enter the elements of second matrix 9 8 7 6 5 4 3 2 1 multiplication of m1*m2 matrices -------------------------------- 30 24 18 84 69 54 138 114 90

Largest and smallest number from array in java

//File name--> MinMax.java import java.io.*; class MinMax{ public static void main(String args[])throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n,min=0,max=0; System.out.println("Enter number of element you want in array."); n=Integer.parseInt(br.readLine()); int[] a=new int[n]; for(int i=0;i a[i]) min=a[i]; if(max OUTPUT javac MinMax.java java MinMax Enter number of element you want in array. 10 Enter elementa[0]: -5 Enter elementa[1]: 11 Enter elementa[2]: 88 Enter elementa[3]: 77 Enter elementa[4]: 66 Enter elementa[5]: 55 Enter elementa[6]: 44 Enter elementa[7]: 33 Enter elementa[8]: 22 Enter elementa[9]: 11 Content of Array: -5 11 88 77 66 55 44 33 22 11 Largest element from array is:88 Smallest element from array is:-5

Armstrong number in java

//File name--> Armstrong.java import java.io.*; class Armstrong{ public static void main(String args[])throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int no,temp,sum=0,rem=0; System.out.println("Enter number:"); no=temp=Integer.parseInt(br.readLine()); while(no>0) { rem=no%10; sum+=(rem*rem*rem); no/=10; } if(sum==temp) { System.out.println("given number "+temp+" is Armstrong number."); } else { System.out.println("given number "+temp+" is not Armstrong number."); } } } OUTPUT javac Armstrong.java java Armstrong Enter number: 123 given number 123 is not Armstrong number. java Armstrong Enter number: 153 given number 153 is Armstrong number. java Armstrong Enter number: 307 given number 307 is not Armstrong number. java Armstrong Enter number: 370 given number 370 is Armstrong number.

Sum of digit in java

//File name-->SumOfDigit.java import java.io.*; class SumOfDigit{ public static void main(String args[])throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int no,sum=0,temp; System.out.println("Enter number:"); no=temp=Integer.parseInt(br.readLine()); while(no>0) { sum+=(no%10); no=no/10; } System.out.println("Sum of Digit for number "+temp+" is:"+sum); } } OUTPUT javac SumOfDigit.java java SumOfDigit Enter number: 12345 Sum of Digit for number 12345 is:15

Calculator using switch case in java

//File name--> Calculator.java import java.io.*; class Calculator{ public static void main(String args[])throws Exception { int n1,n2; String choice; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter number1:"); n1=Integer.parseInt(br.readLine()); System.out.println("press \n + for addition \n - for subtraction \n * for multiplication \n / for division: "); choice=br.readLine(); System.out.println("Enter number2:"); n2=Integer.parseInt(br.readLine()); switch(choice) { case "+": System.out.println("Addition: "+n1+"+"+n2+" is:"+(n1+n2)); break; case "-": System.out.println("Subtraction:"+n1+"-"+n2+" is:"+(n1-n2)); break; case "*": System.out.println("Multiplication:"+n1+"*"+n2+" is:"+(n1*n2)); break; case "/...

Fibonacci series in java

//file name--> Fibonacci.java import java.io.*; class Fibonacci{ public static void main(String args[])throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int p=0,c=1,n=p+c,num; System.out.println("Enter number of Series you want:"); num=Integer.parseInt(br.readLine()); for(int i=0;i OUTPUT javac Fibonacci.java java Fibonacci Enter number of Series you want: 10 0 1 1 2 3 5 8 13 21 34

Star patterns in java

//File name--> Pattern.java import java.io.*; class Pattern{ public static void main(String args[])throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter your choice to print different pattern(1-5):"); int choice=Integer.parseInt(br.readLine()); System.out.println("Enter Number of lines you want:"); int n=Integer.parseInt(br.readLine()); switch(choice) { case 1: for(int i=1;i < =n;i++) { System.out.println(); for(int j=1;j < =i;j++) System.out.print(" "); int a=i; for(int k=0;k < =n-i;k++) { System.out.print(" "+a); a+=i; } } break; case 2: for(int i=0;i < n;i++) { System.out.println(); for(int j=0;j < i;j++) System.out.print(" "); for(int k=0;k < n-i;k++) ...

Java program to print all real solutions to the quadratic eq. ax2+b+c=0. Read a,b,c values and use the formula (–b+sqrt(b2 4ac))/2a

Quadratic.java import java.io.*; class Quadratic { public static void main(String args[]) throws Exception { double a,b,c; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter the value of a:"); a=Double.parseDouble(br.readLine()); System.out.println("Enter the value of b:"); b=Double.parseDouble(br.readLine()); System.out.println("Enter the value of c:"); c=Double.parseDouble(br.readLine()); double delta=(b*b)-(4*a*c); if(a==0) { System.out.println("No solution possible"); } else if ( delta == 0 ) { double root = - b / (2 * a); System.out.println("The Real roots are equal:" + root ); } else if(delta OUTPUT javac Quadratic.java java Quadratic Enter the value of a: 2 Enter the value of b: 5 Enter the value of c: 3 The Real roots are unequal -1.0 and -1.5 java Quadratic Enter the value of a: 0 Enter the value of b: 1 Enter...

Area of rectangle in Java

//File name --> Rectangle.java class Rectangle { public static void main(String args[]) { int width=15,height=10; int area=width*height; System.out.println("Area of Rectangle having width "+width+" and height "+height+" is:"+area); } } OUTPUT javac Rectangle.java java Rectangle Area of Rectangle having width 15 and height 10 is:150

VB.net Database Connectivity step by step tutorial

This tutorials will explain you how to create database in VB.net and how to connect database from VB.net application. I have explain all the steps with snapshot so that you can easily follow the steps. CREATE DATABASE IN VISUAL STUDIO 2010 CREATE TABLE IN DATABASE INSERT VALUES IN TABLES CREATE CONNECTION OBJECT AND OPEN CONNECTION DATA ADAPTER AND DATA SET BINDING DATA GRID VIEW TO DATABASE BINDING CONTROL TO DATABASE BINDING FORM WITH DATABASE FOR NAVIGATING USING BINDINGBASEMANAGER  OBJECT COMMAND OBJECT FOR ADD,DELETE,UPDATE OPERATION  Final Output: Download tutorial If you have any query or doubt just leave the comment.

Implementation of Binary Tree in C Programming

#include < stdio.h> #include < conio.h> struct node { int data; struct node *right, *left; }*root,*p,*q; struct node *make(int y) { struct node *newnode; newnode=(struct node *)malloc(sizeof(struct node)); newnode->data=y; newnode->right=newnode->left=NULL; return(newnode); } void left(struct node *r,int x) { if(r->left!=NULL) printf("\n Invalid !"); else r->left=make(x); } void right(struct node *r,int x) { if(r->right!=NULL) printf("\n Invalid !"); else r->right=make(x); } void inorder(struct node *r) { if(r!=NULL) { inorder(r->left); printf("\t %d",r->data); inorder(r->right); } } void preorder(struct node *r) { if(r!=NULL) { printf("\t %d",r->data); preorder(r->left); preorder(r->right); } } void postorder(struct node *r) { if(r!=NULL) { postorder(r->left); postorder(r->right); printf("\t %d",r->data); } } void main() ...

Add two polynomial using Doubly Linked list in C Programming

#include #include typedef struct pnode { float coef; int exp; struct pnode *next; }p; p *getnode(); void main() { p *p1,*p2,*p3; p *getpoly(),*add(p*,p*); void display(p*); clrscr(); printf("\n enter first polynomial."); printf("\n-------------------------"); p1=getpoly(); printf("\n-------------------------"); printf("\n enter second polynomial"); p2=getpoly(); printf("\n-------------------------"); printf("\nthe first polynomial is: "); display(p1); printf("\n-------------------------"); printf("\nthe second polynomial is :"); display(p2); printf("\n-------------------------"); p3=add(p1,p2); printf("\naddition of two polynomial is :\n\n"); display(p3); printf("\n-------------------------"); } p *getpoly() { p *temp,*New,*last; int flag,exp; char ans; float coef; temp=NULL; flag=1; printf("\nenter the polynomial in descending order of...

Circular Linked List in C Programming

/*Operations on Circular linked list */ #include #include typedef struct node { int data; struct node *link; }node; node *start=NULL; node *create(node *); node *display(node *); node *insert_beg(node *); node *insert_end(node *); node *insert_before(node *); node *insert_after(node *); node *delete_beg(node *); node *delete_end(node *); node *delete_node(node *); node *delete_after(node *); node *delete_list(node *); void main() { int choice; clrscr(); do { printf("\n1)Create a List.\n2)display\n3)Insert at beg\n4)Insert at end \n5)Insert before given node\n6)Insert after given node\n7)Delete from beg\n8)Delete from end\n9)Delete given node\n10)Delete node after given node\n11)Delete list"); printf("\n12)Quit"); printf("\nEnter your Choice : "); scanf("%d",&choice); switch(choice) { case 1: start=create(start); printf("\n Linked List created."); break; case 2: start = di...

Doubly Linked List in C Programming

/*Operations on Doubly linked list */ #include #include typedef struct node { int data; struct node *next,*prev; }node; node *start=NULL; node *create(node *); node *display(node *); node *insert_beg(node *); node *insert_end(node *); node *insert_before(node *); node *delete_beg(node *); node *delete_end(node *); node *delete_node(node *); node *delete_after(node *); node *delete_list(node *); main() { int choice; clrscr(); do { printf("\n1)Create a List.\n2)display\n3)Insert at beg\n4)Insert at end \n5)Insert before given node\n6)Delete from beg\n7)Delete from end\n8)Delete given node\n9)Delete node after given node\n10)Delete list"); printf("\n11)Quit"); printf("\nEnter your Choice : "); scanf("%d",&choice); switch(choice) { case 1: start=create(start); printf("\n Linked List created."); break; case 2: start = display(start); break; case 3: start = insert_beg(st...

Singly Linked List in C Programming

#include #include #define NULL 0 void main() { struct node{ int data; struct node *link; }; typedef struct node node; int val,ch,ch2,cnt,loc,flag=0,num; node *first=NULL,*temp,*ptr,*prv,*next; char c='y'; clrscr(); while(c=='y') { printf("\n1.Insert \n2.Delete \n3.Display \n4.Search \n5.Exit"); printf("\n Enter your choice:"); scanf("%d",&ch); switch(ch) { case 1: printf("\n1.Insert beginning \n2.Insert End \n3.Insert before given node\n4.insret after given node"); printf("\nEnter your choice:"); scanf("%d",&ch2); printf("\n Enter value:"); scanf("%d",&val); switch(ch2) { case 1: temp=(node*)malloc(sizeof(node)); temp->data=val; if(first==NULL) temp->link=NULL; temp->link=first; first=temp; break; case 2: temp=(node*)malloc(sizeof(node)); temp->data=val; ...

Circular Queue using Array in C Programming

#include #include #define MAX 3 #define NULL -1 void main() { int Q[MAX],i,j,f=NULL,r=NULL,val,ch,item; clrscr(); while(1) { printf("\n1.Insert \n2.Delete \n3.Display \n4.Exit"); printf("\n Enter Your choice:"); scanf("%d",&val); switch(val) { case 1: if((f==0 && r==(MAX-1))||(f==r+1)) printf("\nCircular Queue Overflow."); else { if(r==MAX-1) r=0; else r++; printf("\n Enter value for circular queue:"); scanf("%d",&item); Q[r]=item; if(f==NULL) f=0; } break; case 2: if(f==NULL) printf("\n circular queue is empty."); else { printf("\n Deleted element is :%d",Q[f]); if(f==r) f=r=NULL; else if(f==(MAX-1)) f=0; else f++; } break; case 3: if(f==NULL) printf("\n Circular queue is empty."); else { ...

Implementation of Queue using Linked List in C Programming

#include #include #define NULL 0 void main() { struct node{ int data; struct node *link; }; typedef struct node node; int val,ch; node *front=NULL,*rear=NULL,*temp; char c='y'; clrscr(); while(c=='y') { printf("\n1.Insert \n2.Delete \n3.Display \n4.Exit"); printf("\n Enter your choice:"); scanf("%d",&ch); switch(ch) { case 1: printf("\n Enter value:"); scanf("%d",&val); temp=(node*)malloc(sizeof(node)); temp->data=val; temp->link=NULL; if(front==NULL) front=rear=temp; else rear->link=temp; rear=temp; break; case 2: if(front==NULL) printf("\n Queue is empty."); else { temp=front; printf("\n Deleted element is:%d",temp->data); if(front==rear) front=rear=NULL; else front=front->link; free(temp); } break; case 3: if(front==NULL) printf(...

Implementation of Queue using array in C Programming

#include< stdio.h> #include< conio.h> #define MAX 3 void main() { int Q[MAX],f=-1,r=-1,ch,val,i; char cho='y'; clrscr(); while(cho=='y' || cho=='Y') { printf("\n1.Insert \n2.Delete \n3.Show \n4.Exit "); printf("\n Enter your choice:"); scanf("%d",&ch); switch(ch) { case 1: if(r>=(MAX-1)) { printf("\n Queue overflow"); } else { printf("\n Enter value:"); scanf("%d",&val); r++; Q[r]=val; if(f==-1) { f=f+1; } } break; case 2: if(f==-1) { printf("\n Queue underflow"); } else { val=Q[f]; printf("\n Deleted element is:%d",val); if(f==r) { f=-1; r=-1; } else f++; } break; case 3: if(f==-1) { printf("\n Queue empty"); } else { printf("\n content of queue:\n"...

Stack Using Linked List in C programming

#include #include #define NULL 0 void main() { struct node{ int data; struct node *link; }; typedef struct node node; int val,ch; node *top=NULL,*temp; char c='y'; clrscr(); while(c=='y') { printf("\n1.Insert \n2.Delete \n3.Display \n4.Exit"); printf("\n Enter your choice:"); scanf("%d",&ch); switch(ch) { case 1: printf("\n Enter value:"); scanf("%d",&val); temp=(node*)malloc(sizeof(node)); temp->data=val; if(top==NULL) temp->link=NULL; temp->link=top; top=temp; break; case 2: if(top==NULL) printf("\n Stack is empty."); else { temp=top; printf("\n Deleted element is:%d",temp->data); top=top->link; } break; case 3: if(top==NULL) printf("\n Stack is empty."); else { temp=top; printf("\n Stack content:"); while(temp!=NULL) ...

Stack using Array in C programming

#include #include #define MAX 3 void main() { int S[MAX],i,val,c,top=-1,loc; char ch='y'; clrscr(); while(ch=='y') { printf("\n1.Push \n2.Pop \n3.Peep \n4.Change \n5.Display \n6.Exit"); printf("\n Enter your choice:"); scanf("%d",&c); switch(c) { case 1: if(top>=(MAX-1)) printf("\n Stack Overflow"); else { top++; printf("\n Enter value:"); scanf("%d",&val); S[top]=val; } break; case 2: if(top==-1) { printf("\n Stack underflow"); } else { printf("\n Deleted element is:%d",S[top]); top--; } break; case 3: printf("\n Enter index number:"); scanf("%d",&loc); if((top-loc)+1 OUTPUT 1.Push 2.Pop 3.Peep 4.Change 5.Display 6.Exit Enter your choice:2 Stack underflow 1.Push 2.Pop 3.Peep 4.Change 5.Display 6.Exit Enter your choi...

Chain Matrix Multiplication in C Programming

#include #include void MatrixChain(long*,long); void pop(long[10][10],long,long); long s[10][10],m[10][10]; void main() { long *p,n,i,j,str,end; clrscr(); printf("\n Enter number of element for p Matrix:"); scanf("%ld",&n); printf("\n Enter dimension for P matrix:"); for(i=0;i OUTPUT Enter number of element for p Matrix:6 Enter dimension for P matrix:30 3 15 5 10 20 8 --------------------M matrix-------------------- 0 1350 675 1275 2775 2175 -1 0 225 375 975 1455 -1 -1 0 750 2500 2400 -1 -1 -1 0 1000 1800 -1 -1 -1 -1 0 1600 -1 -1 -1 -1 -1 0 --------------------S matrix-------------------- -1 1 1 1 1 1 -1 -1 2 3 4 5 -1 -1 -1 3 3 3 -1 -1 -1 -1 4 5 -1 -1 -1 -1 -1 5 ...

Knapsack using Greedy Algorithm in C Programming

# include # include void knapsack(int n, float weight[], float value[], float W) { float x[20], tp= 0; int i, j, u; u=W; for (i=0;i u) break; else { x[i]=1.0; tp= tp+value[i]; u=u-weight[i]; } } if(i OUTPUT ------------------------------------------------------------------------------------ KNAPSACK PROBLEM USING GREEDY APPROACH ------------------------------------------------------------------------------------ Enter number of Objects you want:5 ----------------Enter the weights and values of each object-------------- Enter weight and value for object1:10 20 Enter weight and value for object2:20 30 Enter weight and value for object3:30 66 Enter weight and value for object4:40 40 Enter weight and value for object5:50 60 Enter the capacity of knapsack:100 ------------------------------------------------------------------------------------ weight | 30.00 10.00 20.00 50.00 40.00 value | 66.00 20.00 30.00 60.00 40.00 x ...

Kruskal’s Algorithm For Minimum Spanning Tree in C Programming

#include #include #define INFINITY 999 typedef struct Graph { int v1,v2,length; }GR; GR G[20]; int tot_edge,tot_node; void create(); void krushkal(); int find(int,int[]); void merge(int i,int j,int parent[]); void main() { clrscr(); printf("\n----------------------------------------------------"); printf("\nKRUSHKAL`s MINIMUM SPANNING TREE ALGORITHM"); printf("\n----------------------------------------------------"); create(); printf("\n Enter any key to see Minimum Spanning Tree?"); getch(); krushkal(); getch(); } void create() { int k; printf("\n Enter Number of nodes in the Graph:"); scanf("%d",&tot_node); printf("\n Enter Number of Edges in the Graph:"); scanf("%d",&tot_edge); printf("\n--------Enter edges and length----------\n"); for(k=0;k OUTPUT ---------------------------------------------------- KRUSHKAL`s MINIMUM SPANNING TREE ALGORITHM ----...

make a change using Greedy Algorithm in C Programming

#include #include int C[]={1,5,10,25,100}; void make_change(int n); int bestsol(int,int); void main() { int n; clrscr(); printf("\n------------------------------------------------"); printf("\n MAKING CHANGE USING GREEDY ALGORITHM "); printf("\n------------------------------------------------"); printf("\n Enter amount you want:"); scanf("%d",&n); make_change(n); getch(); } void make_change(int n) { int S[100],s=0,x,ind=0,i; printf("\n----------------AVAILABLE COINS-----------------\n"); for(i=0;i -1;i--) { if((s+C[i]) OUTPUT ------------------------------------------------------------------------------- MAKING CHANGE USING GREEDY ALGORITHM ------------------------------------------------------------------------------- Enter amount you want:196 ---------------------------AVAILABLE COINS------------------------- 1 5 10 25 100 ------------------------------------...

Knapsack Using Backtracking in C Programming

#include #include #define MAX 20 float final_profit; int w[MAX]; int p[MAX]; int n,m; int temp[MAX],x[MAX]; float final_wt; float Bound_Calculation(int,int,int); void BackTracking(int,int,int); void main() { int i; clrscr(); printf("\n-------------------------------------------------------"); printf("\n KNAPSACK PROBLEM USING BACKTRACKING"); printf("\n-------------------------------------------------------"); printf("\n Enter number of Objects you want:"); scanf("%d",&n); printf("\n-------------------------------------------------------"); for(i=1;i final_profit)&&(k==n)) { final_profit=new_cp; final_wt=new_cw; for(j=1;j =final_profit) { temp[k]=0; if(k final_profit)&&(k==n)) { final_profit=cp; final_wt=cw; for(j=1;j OUTPUT ------------------------------------------------------- KNAPSACK PROBLEM USING BACKTRACKING -------------------------------------...

N-Queen Problem C Programming

#include #include #include int board[20]; int count; void print_board(int); void Queen(int,int); int place(int,int); void main() { int n,i,j; clrscr(); printf("\n-------------------------------------------------------"); printf("\n n-Queen problem using Backtracking"); printf("\n-------------------------------------------------------"); printf("\n Enter number of Queen:"); scanf("%d",&n); Queen(1,n); } void print_board(int n) { int i,j; printf("\n-------------Solution %d---------------\n ",++count); for(i=1;i OUTPUT ------------------------------------------------------- n-Queen problem using Backtracking ------------------------------------------------------- Enter number of Queen:4 -------------Solution 1--------------- 1 2 3 4 ------------------------------------------------------- 1 | - Q - - 2 | - - - Q 3 | Q - - - 4 | - - Q - --...

Breath First Search (BFS) in C Programming

#include #include #define MAX 20 #define TRUE 1 #define FALSE 0 int g[MAX][MAX]; int v[MAX]; int Q[MAX]; int n; int front,rear; void create(); void BFS(int); void main() { int i,j; char ans; clrscr(); printf("\n----------------------------------------------------"); printf("\n BREADTH FIRST SEARCH"); printf("\n----------------------------------------------------"); create(); getch(); printf("\n Adjacency Matrix for the graph is:"); printf("\n----------------------------------------------------"); for(i=0;i =MAX) printf("\n Invalid Vertex"); else { printf("\n The Depth First Search of the Graph is:"); printf("\n----------------------------------------------------\n"); BFS(i); printf("\n----------------------------------------------------\n"); } printf("\n Dou want to Traverse By other node?"); ans=getche(); }while(ans=='y' ||...

Depth First Search (DFS) in C Programming

#include #include #define MAX 20 #define TRUE 1 #define FALSE 0 int g[MAX][MAX]; int v[MAX]; int n; void create(); void DFS(); void main() { int i,j; char ans; clrscr(); printf("\n----------------------------------------------------"); printf("\n DEPTH FIRST SEARCH"); printf("\n----------------------------------------------------"); create(); getch(); printf("\n Adjacency Matrix for the graph is:"); printf("\n----------------------------------------------------"); for(i=0;i =MAX) printf("\n Invalid Vertex"); else { printf("\n The Depth First Search of the Graph is:"); printf("\n----------------------------------------------------\n"); DFS(i); printf("\n----------------------------------------------------\n"); } printf("\n Dou want to Traverse By other node?"); ans=getch(); }while(ans=='y' || ans=='Y'); } void create(...

Greatest Common Divisor.in C Programming

#include #include int GCD(int,int); void main() { int n1,n2; clrscr(); printf("\n Enter two numbers for GCD:"); scanf("%d %d",&n1,&n2); printf("\n Greatest common divisor of %d and %d is:%d",n1,n2,GCD(n1,n2)); getch(); } int GCD(int m,int n) { if(n==0) return m; else { if(n>m) { n=n+m; m=n-m; n=n-m; } return GCD(n,m%n); } } OUTPUT Enter two numbers for GCD:5 15 Greatest common divisor of 5 and 15 is:5

Tower Of Hanoi in C Programming

#include #include #include void tower_of_hanoi(int,char,char,char); void main() { int disk,move; clrscr(); printf("\n Enter number of disks:"); scanf("%d",&disk); move=pow(2,disk)-1; printf("\n No. of moves required is:%d",move); printf("\n A-->Source peg\n B-->Destination peg \n C-->Auxiliary peg"); tower_of_hanoi(disk,'A','B','C'); getch(); } void tower_of_hanoi(int disk,char from,char to,char aux) { if(disk==1) { printf("\n move disk %d from %c to %c",disk,from,to); } else { tower_of_hanoi(disk-1,from,aux,to); printf("\n move disk %d from %c to %c",disk,from,to); tower_of_hanoi(disk-1,aux,to,from); } } OUTPUT Enter number of disks:4 No. of moves required is:15 A-->Source peg B-->Destination peg C-->Auxiliary peg move disk 1 from A to C move disk 2 from A to B move disk 1 from C to B move disk 3 from A to C move disk 1 from B to A ...

MVT (Multiprogramming Variable Task) in C Programming

#include #include void main() { int i,os_m,nPage,total,pg[25]; clrscr(); printf("\nEnter total memory size:"); scanf("%d",&total); printf("\nEnter memory for OS:"); scanf("%d",&os_m); printf("\nEnter no. of pages:"); scanf("%d",&nPage); for(i=0;i =pg[i]) { printf("\n Allocate page %d",i+1); total=total-pg[i]; } else printf("\n page %d is not allocated due to insufficient memory.",i+1); } printf("\n External Fragmentation is:%d",total); getch(); } OUTPUT Enter total memory size:1024 Enter memory for OS:256 Enter no. of pages:4 Enter size of page[1]:128 Enter size of page[2]:512 Enter size of page[3]:64 Enter size of page[4]:512 Allocate page 1 Allocate page 2 Allocate page 3 page 4 is not allocated due to insufficient memory. External Fragmentation is:64

Deadlock Prevention using Banker’s Algorithm in C Programming

#include #include void main() { int allocated[15][15],max[15][15],need[15][15],avail[15],tres[15],work[15],flag[15]; int pno,rno,i,j,prc,count,t,total; count=0; clrscr(); printf("\n Enter number of process:"); scanf("%d",&pno); printf("\n Enter number of resources:"); scanf("%d",&rno); for(i=1;i OUTPUT Enter number of process:5 Enter number of resources:3 Enter total numbers of each resources:10 5 7 Enter Max resources for each process: for process 1:7 5 3 for process 2:3 2 2 for process 3:9 0 2 for process 4:2 2 2 for process 5:4 3 3 Enter allocated resources for each process: for process 1:0 1 0 for process 2:3 0 2 for process 3:3 0 2 for process 4:2 1 1 for process 5:0 0 2 available resources: 2 3 0 Allocated matrix Max need 0 1 0| 7 5 3| 7 4 3 3 0 2| 3 2 2| 0 2 0 3 0 2| 9 0 2| 6 0 0 2 1 1| ...

Optimal Page replacement algorithm in C Programming

#include #include int fsize; int frm[15]; void display(); void main() { int pg[100],change[15],nPage,i,j,k,l,index,pf=0,temp,flag=0,flag1=0,found,max; clrscr(); printf("\n Enter frame size:"); scanf("%d",&fsize); printf("\n Enter number of pages:"); scanf("%d",&nPage); for(i=0;i OUTPUT Enter frame size:3 Enter number of pages:12 Enter page[1]:1 Enter page[2]:2 Enter page[3]:3 Enter page[4]:4 Enter page[5]:1 Enter page[6]:2 Enter page[7]:5 Enter page[8]:1 Enter page[9]:2 Enter page[10]:3 Enter page[11]:4 Enter page[12]:5 page | Frame content -------------------------------------- 1 | 1 -1 -1 2 | 1 2 -1 3 | 1 2 3 4 | 1 2 4 1 | 1 2 4 2 | 1 2 4 5 | 1 2 5 1 | 1 2 5 2 | 1 2 5 3 | 3 2 5 4 | 4 2 5 5 | 4 2 ...

Least Recently Used (LRU) Page replacement algorithm in C Programming

#include #include int fsize; int frm[15]; void display(); void main() { int pg[100],valid[15],nPage,i,j,k,l,index,pf=0,temp,flag=0,flag1=0; clrscr(); printf("\n Enter frame size:"); scanf("%d",&fsize); printf("\n Enter number of pages:"); scanf("%d",&nPage); for(i=0;i OUTPUT Enter frame size:3 Enter number of pages:12 Enter page[1]:1 Enter page[2]:2 Enter page[3]:3 Enter page[4]:4 Enter page[5]:1 Enter page[6]:2 Enter page[7]:5 Enter page[8]:1 Enter page[9]:2 Enter page[10]:3 Enter page[11]:4 Enter page[12]:5 page | Frame content -------------------------------------- 1 | 1 -1 -1 2 | 1 2 -1 3 | 1 2 3 4 | 4 2 3 1 | 4 1 3 2 | 4 1 2 5 | 5 1 2 1 | 5 1 2 2 | 5 1 2 3 | 3 1 2 4 | 3 4 2 5 | 3 4 5 ---...

First Come First Serve (FCFS) Page replacement algorithm in C Programming

#include #include int fsize; int frm[15]; void display(); void main() { int pg[100],nPage,i,j,pf=0,top=-1,temp,flag=0; clrscr(); printf("\n Enter frame size:"); scanf("%d",&fsize); printf("\n Enter number of pages:"); scanf("%d",&nPage); for(i=0;i OUTPUT Enter frame size:3 Enter number of pages:12 Enter page[1]:1 Enter page[2]:2 Enter page[3]:3 Enter page[4]:4 Enter page[5]:1 Enter page[6]:2 Enter page[7]:5 Enter page[8]:1 Enter page[9]:2 Enter page[10]:3 Enter page[11]:4 Enter page[12]:5 page | Frame content -------------------------------------- 1 | 1 -1 -1 2 | 1 2 -1 3 | 1 2 3 4 | 4 2 3 1 | 4 1 3 2 | 4 1 2 5 | 5 1 2 1 | 5 1 2 2 | 5 1 2 3 | 5 3 2 4 | 5 3 4 5 | 5 3 4 ---------------------------...

Round Robin (RR) process scheduling algorithm in C Programming

#include #include void main() { int njob,pID[15],aTime[15],bTime[15],jTime[15],taTime[15],wTime[15],i,j,temp,sTime[15],aBtime[15]; int texe=0,qtime,aexe=0; float totalWait,totalTA; clrscr(); printf("\n Enter number of process:"); scanf("%d",&njob); printf("\n Enter quantum time:"); scanf("%d",&qtime); for(i=0;i =qtime) { aexe=aexe+qtime; bTime[i]=bTime[i]-qtime; jTime[i]=aexe; } else { if(bTime[i]!=0) { aexe=aexe+bTime[i]; bTime[i]=0; jTime[i]=aexe; } } } } for(i=0;i OUTPUT Enter number of process:3 Enter quantum time:4 Enter Burst time for process[0]:24 Enter Burst time for process[1]:3 Enter Burst time for process[2]:3 _+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_ | process | burst time | Waiting time | TA time| _+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_ | 0 | 24 | 6 30...