Posts

Showing posts from 2015

Stack Using Linked List in C

#include<stdio.h> #include<conio.h> typedef struct StackLinked { int val; struct StackLinked *next; }sl; sl *push(sl *,int); int pop(sl **); int peek(sl *); int isempty(sl *); void disp(sl *); void main() { sl *top=NULL; int ch,v; while(1) { printf("\n\n1) Push\n\n2) Pop\n\n3) Peek\n\n4) Display\n\n5) Exit"); printf("\n Enter your choice :"); scanf("%d",&ch); switch(ch) { case 1: printf("\n Enter the number you want to push : "); scanf("%d",&v); top=push(top,v); break; case 2:  if(!isempty(top))   {   printf("\n\nYou have popped %d",pop(&top));   }   else   printf("\n\nNothing to pop"); break; case 3: if(!isempty(top))   {   printf("\n\nTop most value is %d",peek(top));   }   else   printf("\nNothing in the stack"); break; case 4: if(!isempty(top))   {   printf("\n\nValues in th...

Binary Tree Creation and traversal using C coding

Image
#include<stdio.h> #include<conio.h> #include<malloc.h> typedef struct tree { int val; struct tree *lch; struct tree *rch; }tr; typedef struct stack { tr *node; struct stack *next; }st; void push(st **,tr *); tr *pop(st **); int isempty(st *); tr *createroot(); void insert(st *); void inorder(tr *); void main() { st *h=NULL; tr *ptr; clrscr(); ptr=createroot(); push(&h,ptr); insert(h); printf("\n\nInorder traversal form of the tree is : "); inorder(ptr); getch(); } tr *createroot() { int v; tr *ptr; printf("\nEnter the values : "); scanf("%d",&v); ptr=(tr *)malloc(sizeof(tr)); ptr->val=v; ptr->lch=ptr->rch=NULL; return(ptr); } void insert(st *h) { tr *ptr,*temp; char ch; int v; while(!isempty(h)) { ptr=pop(&h); printf("\n%d has left child?(y/n) : ",ptr->val); fflush(stdin); scanf("%c",&ch); if(ch=='y' || ch=='Y...

Program Code for Circle drawing

#include<stdio.h> #include<conio.h> #include<graphics.h> #include<math.h> #include<dos.h> void disp(float,int,int); void disp1(float,int,int); void main() { int gd=DETECT,gm,h,k,y,fl=1,m; float r; initgraph(&gd,&gm,"C:\\TC\\BGI"); printf("Enter the radius " ); scanf("%f",&r); printf("Enter the center (h,k) :"); scanf("%d %d",&h,&k); m=r; while(1) {  if(kbhit())  break; if(r<=0) fl=0; if(r>=m) fl=1; if(fl==1) { r--; disp(r,h,k); } else { r++; disp1(r,h,k); } sleep(1); } } void disp(float r,int h,int k) { int x,xe,y; x=0; xe=r/1.414; while(x<xe) { y=sqrt(pow(r,2)-pow(x,2)); putpixel(x+h,y+k,1); putpixel(-x+h,y+k,2); putpixel(x+h,-y+k,3); putpixel(-x+h,-y+k,4); putpixel(y+h,x+k,1); putpixel(-y+h,x+k,2); putpixel(y+h,-x+k,3); putpixel(-y+h,-x+k,4); x++; } } void disp1(float r,int h,int k) { int x,xe,y; x=0; xe=r/1...

Code for Linked List using Java

import java.io.*; class Linked { int a; Linked next; Linked(int g) { a=g; next=null; } void addNode(int g) { Linked temp,node; temp=this; while(temp.next!=null) { temp=temp.next; } node=new Linked(g); temp.next=node; } void displ() { Linked temp; temp=this; while(temp!=null) { System.out.println(temp.a); temp=temp.next; } } } class LinkedPrg { public static void main(String []at) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int p; char ch; System.out.println("Enter values(less than 0 to exit) : "); p=Integer.parseInt(br.readLine()); Linked ob=new Linked(p); for(;;) { System.out.println("Enter values (less than 0 to exit) :  "); p=Integer.parseInt(br.readLine()); if(p<0) break; ob.addNode(p); } System.out.println("Values in the linked list are"); ob.displ(); } }

code for impementing sorting using Selection Sort algorithm

//code for selection sort with intermediate PASS result #include<stdio.h> int selectsmallest(int ar[],int i,int m) { int j,loc,min,k; min=ar[i]; loc=i; for(j=i+1;j<m;j++) { if(ar[j]<min) { min=ar[j]; loc=j; } } printf("\nPass %d :",i); for(k=0;k<m;k++) printf("%d",ar[k]); printf("\n\nsmallest element is %d at %d position",ar[loc],loc); printf("\nswap this value with %d position",i); return loc; } void selectionsort(int ar[],int m) { int loc,j,i,k,temp; for(i=0;i<m;i++) { loc=selectsmallest(ar,i,m); //printf("%d",ar[loc]); temp=ar[loc]; ar[loc]=ar[i]; ar[i]=temp; } } void main() { int i,m,ar[10]; printf("\nEnter the length of the array : "); scanf("%d",&m); printf("\nEnter the values : "); for(i=0;i<m;i++) scanf("%d",&ar[i]); selectionsort(ar,m); printf("\nafter sorting : "); for(i=0;i<m;i++) printf(...

Program code for polynomial addition using C

/*code for adding two polynomials. please avoid giving duplicate power term. you can enter term values (coefficient and power) in any order. this code is designed for sorting them in appropriate order */ #include<stdio.h> #include<conio.h> #include<alloc.h> typedef struct Polynomial{ int coeff; int powe; struct Polynomial *next; }pl; pl *create(); pl *polyadd(pl *,pl *); void bubblesort(pl *); void disp(pl *); void main() { pl *h1,*h2,*h3; clrscr(); printf("\n\nEnter value for first polynomial : "); h1=create(); printf("\n\nEnter value for second polynomial : "); h2=create(); bubblesort(h1); bubblesort(h2); printf("\n\nFirst Polynomial is : "); disp(h1); printf("\n\nFirst Polynomial is : "); disp(h2); h3=polyadd(h1,h2); printf("\n\nAdded result of two Polynomial is : "); disp(h3); getch(); } pl *create() { pl *temp,*ptr,*h=NULL; int v,u; char ch; while(1) { printf(...

C program code for implementing matrix using linear linked list

//matrix using linked list #include<stdio.h> #include<conio.h> typedef struct linked { int val; struct linked *next; }lnk; typedef struct linkedaddr { lnk *node; struct linkedaddr *link; }lnkadr; lnk *createcol(); lnkadr *createrow(); void disprow(lnkadr *); void dispcol(lnk *); void main() { lnkadr *h; clrscr(); h=createrow(); printf("Values in the matrix : \n\n\n"); disprow(h); getch(); } lnkadr *createrow() { //lnk *h; lnkadr *head=NULL,*temp,*ptr; char ch; while(1) { temp=(lnkadr *) malloc(sizeof(lnkadr)); temp->node=createcol(); temp->link=NULL; if(head==NULL) { head=temp; } ptr->link=temp; ptr=temp; printf("Do you have more row in the matrix ?(y/n) : "); fflush(stdin); scanf("%c",&ch); if(ch=='n' || ch=='N') return head; } } lnk *createcol() { lnk *h=NULL,*ptr,*temp; int v; while(1) { printf("Enter value for the cell of the matrix (0 to exit...

Java Program code for implementing array of objects

import java.util.*; class Sports { int cr; boolean ingame,outgame; Sports(boolean ig,boolean og) { cr=0; ingame=ig; outgame=og; } void cre() { if(ingame==true) cr+=5; if(outgame==true) cr+=10; } } class Marksheet extends Sports { int m1,m2,m3,tot,avg; char grade; Marksheet(int a,int b,int c,boolean ig,boolean og) { super(ig,og); m1=a; m2=b; m3=c; } void calculate() { cre(); tot=m1+m2+m3; avg=tot/3; if(avg>=90) { grade='O'; cr+=15; } else if(avg>=80) { grade='E'; cr+=10; } else if(avg>=70) { grade='A'; cr+=5; } else if(avg>=60) grade='B'; else if(avg>=50) grade='C'; else if(avg>=40) grade='D'; else grade='F'; } } class Student extends Marksheet { int roll; String name; String addr; String phno; Student(int r,String nm,String adr,String phn,int a,int b,int c,boolean ig,boolean og) { super(a,b,c,ig,og); roll=r; name=nm; addr=adr; phno=phn; }...

C Program code for solving Josephus problem using circular linked list

//Josephus problem using circular linked list #include<stdio.h> #include<conio.h> typedef struct circular { int val; struct circular *next; }cir; cir *create(); void disp(cir *); void insertafter(cir *,int); cir *insertbefore(cir *,int); cir *del(cir *,int); cir *josephus(cir*,int); void main() { int ch,v,p; cir *head; while(1) { printf("\n1) Create \n2) Insert after\n3) Insert before \n4) Delete \n5) Display \n6) Josephus Problem\n7) Exit"); printf("\nEnter your choice : "); scanf("%d",&ch); switch(ch) { case 1: head=create(); break; case 2: printf("\nEnter the node value after which you want to insert the new node : "); scanf("%d",&p); insertafter(head,p); break; case 3: printf("\nEnter the node value before which you want to insert the new node :"); scanf("%d",&p); head=insertbefore(head,p); break; case 4: printf("\nEnter the node ...

Program code for bubble sort using linked list

//code for bubble sort using linked list #include<stdio.h> #include<conio.h> #include<alloc.h> typedef struct linked { int val; struct linked *next; }lnk; lnk *create(); void bubblesort(lnk *); void disp(lnk *); void main() { lnk *h; printf("\n\nEnter the values (0 to exit) : "); h=create(); printf("\n\nValues in the linked list before sorting are : "); disp(h); bubblesort(h); printf("\n\nValues in the linked list after sorting are : "); disp(h); getch(); } lnk *create() { lnk *temp,*ptr,*h=NULL; int v; while(1) { scanf("%d",&v); if(v==0) return h; temp=(lnk*)malloc(sizeof(lnk)); temp->val=v; temp->next=NULL; if(h==NULL) h=temp; else ptr->next=temp; ptr=temp; } } void disp(lnk *h) { while(h!=NULL) { printf("%d",h->val); h=h->next; } } void bubblesort(lnk *h) { int v; lnk *ptr,*loc; loc=h; while(h!=NULL) { ptr=loc; whil...

Program code for split up linked list into odd and even value

//Split up two linked list into even and odd value #include<stdio.h> #include<conio.h> #include<alloc.h> typedef struct linked { int val; struct linked *next; }lnk; lnk *create(); void splitlink(lnk *,lnk **,lnk **); void disp(lnk *); void main() { lnk *h1=NULL,*h2=NULL,*h; printf("\n\nEnter the values (0 to exit) : "); h=create(); printf("\n\nValues in the linked list are : "); disp(h); splitlink(h,&h1,&h2); printf("\n\nValues in the first linked list are : "); disp(h1); printf("\n\nValues in the second linked list are : "); disp(h2); getch(); } lnk *create() { lnk *temp,*ptr,*h=NULL; int v; while(1) { scanf("%d",&v); if(v==0) return h; temp=(lnk*)malloc(sizeof(lnk)); temp->val=v; temp->next=NULL; if(h==NULL) h=temp; else ptr->next=temp; ptr=temp; } } void disp(lnk *h) { while(h!=NULL) { printf("%d",h->val); h...

Program code to merge two sorted linked list in sorted order

//Merge two already sorted linked list in sorted order #include<stdio.h> #include<conio.h> #include<alloc.h> typedef struct linked { int val; struct linked *next; }lnk; lnk *create(); lnk *merge(lnk *,lnk *); void disp(lnk *); void main() { lnk *h1,*h2,*h; printf("\n\nEnter the values (0 to exit) : "); h1=create(); printf("\n\nEnter the values (0 to exit) : "); h2=create(); printf("\n\nValues in the first linked list are : "); disp(h1); printf("\n\nValues in the second linked list are : "); disp(h2); h=merge(h1,h2); printf("\n\nValues in the merged linked list are : "); disp(h); getch(); } lnk *create() { lnk *temp,*ptr,*h=NULL; int v; while(1) { scanf("%d",&v); if(v==0) return h; temp=(lnk*)malloc(sizeof(lnk)); temp->val=v; temp->next=NULL; if(h==NULL) h=temp; else ptr->next=temp; ptr=temp; } } void disp(lnk *h) { while(...

2D array using java

class JavaArr { public static void main(String []ar) { int [][]a=new int [5][5]; int k; for(int i=0;i<5;i++) { k=1; for(int j=0;j<5;j++) { a[i][j]=k++; } } System.out.println("Values in the array are :"); for(int i=0;i<5;i++) { for(int j=0;j<5;j++) { System.out.print("   "+a[i][j]); } System.out.println(); } } } I/O : array is declared and value is passed through loop and values are displayed. type the program and run it , I hope its very simple to understand.

Program code for inserting node at any position in Linked List

//C Program code for inserting new node at  any position you like #include<stdio.h> #include<conio.h> #include<alloc.h> typedef struct linked { int val; struct linked *next; }lnk; lnk *insert(lnk *,int,int); void disp(lnk *); void main() { lnk *h=NULL; int ch,pos,v; while(1) { printf("\n1) Insert at any position \n2) Display \n3) Exit"); printf("\nEnter your choice : "); scanf("%d",&ch); switch(ch) { case 1: printf("\n Enter the value : "); scanf("%d",&v); printf("\n Enter the posiotion of new node : "); scanf("%d",&pos); h=insert(h,v,pos); break; case 2: printf("\n\nValues are :"); disp(h); break; case 3: exit(0); default: printf("\n\nWrong choice"); } } } lnk *insert(lnk *h,int v,int po) { lnk *ptr,*temp,*pre; int i; temp=(lnk*)malloc(sizeof(lnk)); temp->val=v; temp->next=NULL; if(h==NULL) { printf(...

Program code to draw a line using DDA in C

#include<stdio.h> #include<conio.h> #include<graphics.h> int round(float x) { int p; p=x; return p; } void main() { int gd=DETECT,gm,x1,y1,dx,dy,x2,y2,length,i,x,y; initgraph(&gd,&gm,"C:\\TC\\BGI"); printf("Enter the starting points (x,y) : "); scanf("%d %d",&x1,&y1); printf("Enter the ending points (x,y) : "); scanf("%d %d",&x2,&y2); if(abs(x2-x1)>=abs(y2-y1)) length=abs(x2-x1); else length=abs(y2-y1); i=1; dx=(x2-x1)/length; dy=(y2-y1)/length; x=x1; y=y1; while(i<=length) { putpixel(round(x),round(y),2); //x1=x1+dx; y=y+dy; i++; } i=1; x=x1; y=y1; while(i<=length) { putpixel(round(x),round(y),2); x=x+dx; //y1=y1+dy; i++; } i=1; x=x1; y=y1; while(i<=length) { putpixel(round(x),round(y),3); x=x+dx; y=y+dy; i++; } getch(); closegraph(); }

Program code for converting Infix expression into Postfix expression

#include<stdio.h> #include<conio.h> #define MAX 100 typedef struct stack {  char data[MAX];  int top; }stack; int getpriority(char); int isempty(stack *); int isfull(stack *); char pop(stack *); void push(stack *,char); char peek(stack *); void intopost(char [],char []); void main() { char str[50],str1[50]; printf("Enter the infix expression: "); gets(str); intopost(str,str1); printf("Post fix expression is : "); puts(str1); getch(); } // Following function is converting infix into postfix notation void intopost(char str[],char str1[]) { stack s; char x; int i,j; s.top=-1; clrscr(); i=j=0;   while(str[i]!='\0')   {     if(isalnum(str[i]))  str1[j++]=str[i];     else        if(str[i] == '(')   push(&s,'(');        else        { if(str[i] == ')')     while((x=pop(&s))!='(')    ...

SPECIAL STACK USING C

//This is a special stack in which popped value is replaced with -1 and value insertion is done at the  position where -1 is found first from the bottom. #include<stdio.h> #include<conio.h> #define max 50 typedef struct stack { int ar[max]; int top; }st; void push(st *,int); int pop(st *); int peek(st); int isfull(st); int isempty(st); void disp(st); void main() { int ch,g; st s; s.top=-1; while(1) { printf("\n1)Push\n2)Pop\n3)Peek\n4)Disp\n5)Exit"); printf("\n Enter your choice ; "); scanf("%d",&ch); switch(ch) { case 1: if(!isfull(s)) { printf("Enter the value : "); scanf("%d",&g); push(&s,g); } else printf("No More Space"); break; case 2: if(!isempty(s)) printf("Popped value is %d",pop(&s)); else printf("Nothing to display "); break; case 3: if(!isempty(s)) { printf("Top value is %d",peek(s)); } els...

Stack for storing character value using pointer

// stack using pointer for character array #include<stdio.h> #include<conio.h> typedef struct stack { int top; char ar[50]; }st; void push(st*,char); char pop(st*); char peek(st); int isempty(st); int isfull(st); void disp(st); void main() { int ch; char m; st s; s.top=-1; while(1) { printf("\n\n1) Push\n2) Pop\n3) Peek\n4) Disp\n5) Exit"); printf("\nEnter the choice : "); scanf("%d",&ch); switch(ch) { case 1: if(!isfull(s)) { printf("Enter the value : "); fflush(stdin); scanf("%c",&m); push(&s,m); } else printf("\nNo more space ..... "); break; case 2: if(!isempty(s)) { printf("\n\nThe popped value is %c",pop(&s)); } else printf("\nNothing to display ....."); break; case 3: if(!isempty(s)) { printf("\n\nThe top most value is %c",peek(s)); } else printf("\nNothing to display .....");...

Stack using structure pointer

#include<stdio.h> #include<conio.h> typedef struct stack { int top; int ar[50]; }st; void push(st*,int); int pop(st*); int peek(st); int isempty(st); int isfull(st); void disp(st); void main() { int m,ch; st s; s.top=-1; while(1) { printf("\n\n1) Push\n2) Pop\n3) Peek\n4) Disp\n5) Exit"); printf("\nEnter the choice : "); scanf("%d",&ch); switch(ch) { case 1: if(!isfull(s)) { printf("Enter the value : "); scanf("%d",&m); push(&s,m); } else printf("\nNo more space ..... "); break; case 2: if(!isempty(s)) { printf("\n\nThe popped value is %d",pop(&s)); } else printf("\nNothing to display ....."); break; case 3: if(!isempty(s)) { printf("\n\nThe top most value is %d",peek(s)); } else printf("\nNothing to display ....."); break; case 4: if(!isempty(s)) { printf("\n\nThe values are...

stack using structure

#include<stdio.h> #include<conio.h> typedef struct stack { int top; int ar[50]; }st; void push(st*,int); int pop(st*); int peek(st); int isempty(st); int isfull(st); void disp(st); void main() { int m,ch; st s; s.top=-1; while(1) { printf("\n1) Push\n2) Pop\n3) Peek\n4) Disp\n5) Exit"); printf("\nEnter the choice : "); scanf("%d",&ch); switch(ch) { case 1: if(!isfull(s)) { printf("Enter the value : "); scanf("%d",&m); push(&s,m); } else printf("No more space ..... "); break; case 2: if(!isempty(s)) { printf("The popped value is %d",pop(&s)); } else printf("Nothing to display ....."); break; case 3: if(!isempty(s)) { printf("The top most value is %d",peek(s)); } else printf("Nothing to display ....."); break; case 4: if(!isempty(s)) { printf("The values are"); disp(s); } ...

Program to pass 2D array in a function in C

#include<stdio.h> void func(int a[][10],int k,int l) { int i,j; for(i=0;i<k;i++) { for(j=0;j<l;j++) { printf("%d",a[i][j]); } printf("\n"); } } int main() { int ar[10][10],n,i,m,j; printf("Enter the row & column of the matrix"); scanf("%d %d",&m,&n); //ar=(int *)calloc(m,sizeof(int)); for(i=0;i<m;i++) { //*ar=(int *)calloc(n,sizeof(int)); for(j=0;j<n;j++) { scanf("%d",&ar[i][j]); } } func(ar,m,n); } O/P: Enter the row & column of the matrix: 4 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1234 1234 1234 1234 after taking 16 values it will just print them in matrix form .....

Implement Linked List using Java

import java.util.*; import java.io.*; import java.lang.*; class Linked { int val; Linked next; Linked(int g) { val=g; next=null; } void addNode(int p) { Linked ob=new Linked(p); Linked t; t=this; while(t.next!=null) { t=t.next; } t.next=ob; } void disp() { Linked t; t=this; while(t!=null) { System.out.println(t.val); t=t.next; } } } class LinkedPrg { public static void main(String []ar) throws IOException { Scanner cin=new Scanner(System.in); int p,g; char ch='y'; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter the value for the head node : "); g=Integer.parseInt(br.readLine()); Linked ob=new Linked(g); while(true) { System.out.println("Do you want to continue?(y/n) : "); ch=br.readLine().charAt(0); if(ch=='n' || ch=='N') break; System.out.println("Enter the value for the node : "); g=Integer.parseInt(br.readLine()); ...

Bubble Sort using Command Line Arguments in JAVA

class BubblePrg { public static void main(String []a) { int ar[],m,i,j,temp,k; m=10; ar=new int[m]; i=0; for(String x:a) { ar[i++]=Integer.parseInt(x); } System.out.println("Before Sorting Array is : "); for(i=0;i<m;i++) System.out.print(ar[i]+","); for(i=0;i<m;i++) { for(j=0;j<m-i-1;j++) { if(ar[j]>ar[j+1]) { temp=ar[j]; ar[j]=ar[j+1]; ar[j+1]=temp; } } System.out.println("\n \nAfter Pass : "+i); for(k=0;k<m;k++) System.out.print(ar[k]+","); } System.out.println("\n \nAfter Sorting Array is : "); for(i=0;i<m;i++) System.out.print(ar[i]+","); } } I/O :  after compiling the java source code run it as follows : $> java BubblePrg 12 21 23 34 4 22 65 56 76

JAVA program to add two distance

class Distance { int ft,inch; Distance(int f,int i) { ft=f; inch=i; } Distance addDist(Distance ob,Distance ob1) { int f=0,i=0; i=inch+ob.inch+ob1.inch; if(i>=12) { f=i/12; i=i%12; } f=ft+ob.ft+f+ob1.ft; Distance ob2=new Distance(f,i); return ob2; } void dispDist() { System.out.println(ft+"ft "+inch+"inch"); } } class AddDistance { public static void main(String []ar) { Distance ob=new Distance(12,22); Distance ob1=new Distance(13,12); Distance ob2=new Distance(11,11); Distance ob3; ob3=ob.addDist(ob1,ob2); ob.dispDist(); ob1.dispDist(); ob2.dispDist(); ob3.dispDist(); } } I/O: run this program , its clear to understand ....

JAVA program to add , subtract two Rational Number

class Ration { int num,den; Ration(int n,int d) { if(d<n) { num=d; den=n; } else { num=n; den=d; } } Ration() { den=0; num=0; } void disp() { System.out.println("Value is : "+num+"/"+den); } void adjust() { int a,b,t; b=num; a=den; while(a%b!=0) { t=a%b; a=b; b=t; } num=num/b; den=den/b; } Ration subRation(Ration ob) { Ration ob1=new Ration(); int t; t=den*ob.den; ob1.num=num*(t/den)-ob.num*(t/ob.den); ob1.den=t; ob1.adjust(); return ob1; } Ration addRation(Ration ob) { Ration ob1=new Ration(); int t; t=den*ob.den; ob1.num=ob.num*(t/ob.den)+num*(t/den); ob1.den=t; ob1.adjust(); return ob1; } } class Rational { public static void main(String p[]) { Ration ob=new Ration(4,6); Ration ob1=new Ration(2,4); Ration ob2; ob.adjust(); ob1.adjust(); ob.disp(); ob1.disp(); ob2=ob.addRation(ob1); ob2.disp(); ob2=ob.subRation(ob1); ob2.disp(); } }

JAVA Program to add, multiply two Matrix object

class Matrix { int m,n; int ar[][]; Matrix(int a,int b) { int i; m=a; n=b; ar=new int[a][]; for(i=0;i<m;i++) ar[i]=new int[b]; } void insertData() { int i,j,k=1; for(i=0;i<m;i++) { k=1; for(j=0;j<n;j++) ar[i][j]=k++; } } Matrix addMat(Matrix ob) { int i,j; Matrix ob1=new Matrix(m,n); if(m==ob.m && n==ob.n) { for(i=0;i<m;i++) for(j=0;j<n;j++) ob1.ar[i][j]=ar[i][j]+ob.ar[i][j]; } else System.out.println("Condition not matched "); return ob1; } Matrix multiMat(Matrix ob) { int i,j,k; Matrix ob1=new Matrix(m,n); if(n==ob.m) { for(i=0;i<m;i++) { for(j=0;j<ob.n;j++) { ob1.ar[i][j]=0; for(k=0;k<n;k++) ob1.ar[i][j]+=ar[i][k]*ob.ar[k][j]; } } } else System.out.println("Condition not matched "); return ob1; } void disp() { int i,j; for(i=0;i<m;i++) { for(j=0;j<n;j++) System.out.print(ar[i][j]+" "); System.out.println(); } } } class AddMatrix {...

Circular Queue using Linked List ....

#include<stdio.h> #include<conio.h> typedef struct circular { int val; struct circular *next; }cir; cir *createnode(cir *,int ); void enqueue(cir **,int); int dequeue(cir **); int isempty(cir *); int peek(cir *); void disp(cir *); void main()  {  cir *h=NULL;  int v,p;  while(1)  {  printf("\n 1.insert \n2.delete \n3.peek \n4.display \n5.exit");  printf("enter the choice");  scanf("%d",&p);  switch(p)  {  case 1:printf("enter the value"); scanf("%d",&v); enqueue(&h,v); break;  case 2:printf("deleted value is:"); scanf("%d",&v); break;  case 3:printf("front value: "); scanf("%d",&v); break;  case 4:printf("display the value"); disp(h); break;  case 5: exit(0);  default:printf("not a proper choice");  }  }  }  cir *createnode(cir *h,int v)  {  cir *ptr,*temp;  temp=(cir*)malloc(sizeof(c...

Polynomial Addition using Linked List

#include<stdio.h> #include<stdlib.h> typedef struct poly { int coff,powr; struct poly *next; }pl; void addnode(pl **, int ,int); void creatpoly(pl **); void addpoly(pl *,pl *,pl **); void display(pl *); void main() { int n; pl *pl1,*pl2,*pl3; pl1=pl2=pl3=NULL; clrscr(); printf("\nEnter 1st Polynomial\n"); creatpoly(&pl1); display(pl1); printf("\nEnter 2nd Polynomial\n"); creatpoly(&pl2); display(pl2); printf("\nSum Poly\n"); addpoly(pl1,pl2,&pl3); display(pl3); getch(); } void creatpoly(pl **ptr) {    int cof,pow,temp=10;    char ch;    while(1)    { printf("\nEnter Coff of X : "); scanf("%d",&cof); printf("\nEnter Powr of X : "); scanf("%d",&pow); if(pow<temp) addnode(ptr,cof,pow); else { printf("\nPower must be lesser than the previous term :"); continue; } temp=pow; printf("\nDo you ...

Queue using structure

#include<stdio.h> #include<conio.h> #include<stdlib.h> #define max 50 typedef struct queue    {     int ar[max];     int rear,front;    }qu;      void enqueue(qu *ps,int a);    int dequeue(qu *ps);    int isempty(qu *ps);    int isfull(qu *ps);    int peek(qu *ps);    void disp(qu *ps);    void init(qu *ps);      int main()    {     qu q;     int x,val;     init(&q);     while(1)      {     printf("press \n 1.enter\n2.delete\n3.Peek\n4.Display\n5.Exit\n");     scanf ("%d",&x);     switch(x)      {       case 1: if(!isfull(&q))              {               printf("ente...

Operations of Linear Linked List ...

#include<stdio.h> #include<conio.h> #include<stdlib.h> typedef struct linked {     int val;     struct linked *next; }lnk; lnk *create(lnk*,int); lnk *insertbefore(lnk*,int); void insertafter(lnk*,int); lnk *del(lnk*,int); void disp(lnk*); void main() {     lnk *h=NULL;     int v,ch;     while(1)     { printf("\n===================================="); printf("\n1)Create\n2)Insert Before\n3)Insert After\n4)Delete\n5)Display\n6)Exit"); printf("\n===================================="); printf("\n\nEnter your choice:"); scanf("%d",&ch); switch(ch) {    case 1: printf("\nEnter the value you want to enter:");    scanf("%d",&v);    h=create(h,v);    break;    case 2: printf("\nEnter the value before which you want to Insert:");    scanf("%d", &v);    h=insertbefore(h,v); ...

Highest total marks holder using Structure

#include<stdio.h> #include<conio.h> struct Student {        int roll;        char name[25];        char addr[25];        int mark[5];        int total;        float avg;        char grad;        };       int checkHighest(struct Student [],int); void getVal(struct Student [],int); void printDetail(struct Student [],int); int main() {      struct Student std[50];      int m,t,i;          printf("\nEnter the number of students :");      scanf("%d",&m);      printf("\nEnter the student details : ");          getVal(std,m);              printf("\nStudent details : ");      for(i=0;i<m;i++)      ...