• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
projectsgeek

ProjectsGeek

Download Mini projects with Source Code, Java projects with Source Codes

  • Home
  • Java Projects
  • C++ Projects
  • VB Projects
  • PHP projects
  • .Net Projects
  • NodeJs Projects
  • Android Projects
    • Project Ideas
      • Final Year Project Ideas
      • JSP Projects
  • Assignment Codes
    • Fundamentals of Programming Language
    • Software Design Laboratory
    • Data Structure and Files Lab
    • Computer Graphics Lab
    • Object Oriented Programming Lab
    • Assembly Codes
  • School Projects
  • Forum

C Assignments

Circular Link List using C Language

April 5, 2011 by ProjectsGeek Leave a Comment

Circular Link List using C Language

Represent single variable polynomial as a circular link list. Accept the terms in the polynomial in any order, i.e. not necessarily in the decreasing order of exponent. Sort while creating polynomial in the decreasing order of exponent and write a menu driven program to perform Circular Link List   display, addition, multiplication and evaluation.

 Concept of Circular Link List organization, singly linked list, doubly linked list, circular linked list.Linked list as ADT. Representation and manipulations of polynomials using linked lists,comparison of sequential linked organization with linked organization, concept Generalized Linked List.

Circular Link List using C Language Code

 #include  
 #include  
 #include  
 #include  
 typedef struct poly1  
 {  
 int pow;  
 float coeff;  
 struct poly1 *link;  
 }poly1;  
 poly1 *create();  
 void display(poly1 *);  
 poly1 *mul(poly1 *,poly1 *);  
 poly1 *add(poly1 *,poly1 *);  
 float evaluate(poly1 *,float);  
 poly1 *alloc();  
 int valid();  
 float validf();  
 poly1 *freeall(poly1 *);  
 void main()  
 {  
 poly1 *p1=NULL,*p2=NULL,*p3;  
 int ch,ch1;  
 float m;  
 float dummy;  
 &dummy;  
 clrscr();  
 do  
 {  
 clrscr();  
 printf("\n\t\tOPERATION ON POLYNOMIALS");  
 printf("\n\t\t1.CREATE\n\t\t2.DISPLAY\n\t\t3.ADDITION\n\t\t4.MULTPLICATION\n\t\t5.EVALUATION\n\t\t6.EXIT");  
 printf("\n\t\tENTER UR CHOICE:");  
 ch=valid();  
 switch(ch)  
 {  
 case 1: do  
 {  
 clrscr();  
 printf("\nCREATING POLYNOMIAL");  
 printf("\n\t\t1.FIRST POLY\n\t\t2.SECOMND POLY\n\t\t3.EXIT");  
 printf("\n\t\tENTER UR CHOICE:");  
 ch1=valid();  
 switch(ch1)  
 {  
 case 1: if(p1!=NULL)  
 freeall(p1);  
 printf("\n\t\tFIRST POLY");  
 p1=create();  
 break;  
 case 2: if(p2!=NULL)  
 freeall(p2);  
 printf("\n\t\tSECOND POLY");  
 p2=create();  
 break;  
 case 3:break;  
 default:printf("INVALID CHOICE");  
 }  
 }while(ch1!=3);  
 break;  
 case 2: do  
 {  
 clrscr();  
 printf("\nDISPLAYING POLYNOMIAL");  
 printf("\n\t\t1.FIRST POLY\n\t\t2.SECOMND POLY\n\t\t3.EXIT");  
 printf("\n\t\tENTER UR CHOICE:");  
 ch1=valid();  
 switch(ch1)  
 {  
 case 1: if(p1==NULL)  
 printf("\nEMPTY POLY");  
 else  
 {  
 printf("\n\t\tFIRST POLY");  
 display(p1);  
 }  
 getch();  
 break;  
 case 2: if(p2==NULL)  
 printf("\nEMPTY POLY");  
 else  
 {  
 printf("\n\t\tSECOND POLY");  
 display(p2);  
 }  
 getch();  
 break;  
 case 3:break;  
 default:printf("INVALID CHOICE");  
 getch();  
 }  
 }while(ch1!=3);  
 break;  
 case 3: if(p1==NULL&&p2==NULL)  
 printf("\nADDITION NOT POSSIBLE");  
 else  
 {  
 printf("\n\t\tADDITION");  
 p3=add(p1,p2);  
 if(p3==NULL)  
 printf("p3 is empty");  
 else  
 display(p3);  
 }  
 getch();  
 break;  
 case 4: if(p1==NULL&&p2==NULL)  
 printf("\nMULTIPLICATION NOT POSSIBLE");  
 else  
 {  
 printf("\n\t\tFIRST POLY*SECOND POLY");  
 p3=mul(p1,p2);  
 display(p3);  
 }  
 getch();  
 break;  
 case 5: do  
 {  
 clrscr();  
 printf("\n\t\tEVALUATION");  
 printf("\n\t\tENTER THE VALUE OF x:");  
 m=validf();  
 printf("\n\t\tEVALUATION ON");  
 printf("\n\t\t1.FIRST POLY\n\t\t2.SECOMND POLY\n\t\t3.EXIT");  
 printf("\n\t\tENTER UR CHOICE:");  
 ch1=valid();  
 switch(ch1)  
 {  
 case 1: if(p1==NULL)  
 printf("\nEVALUATION CANT BE DONE ON EMPTY POLY");  
 else  
 {  
 printf("\n\t\tFIRST POLY");  
 m=evaluate(p1,m);  
 printf("\n\tevaluation\t%f",m);  
 }  
 getch();  
 break;  
 case 2: if(p2==NULL)  
 printf("\nEVALUATION CANT BE DONE ON EMPTY POLY");  
 else  
 {  
 printf("\n\t\tSECOND POLY");  
 m=evaluate(p2,m);  
 printf("\n\tevaluation\t%f",m);  
 }  
 getch();  
 break;  
 case 3:break;  
 default:printf("INVALID CHOICE");  
 getch();  
 }  
 }while(ch1!=3);  
 break;  
 case 6: break;  
 default:printf("\n\t\tINVALID CHOICE");  
 getch();  
 }  
 }while(ch!=6);  
 }  
 /*poly1 *create()  
 {  
 poly1 *nw,*p,*t;  
 p=NULL;  
 do  
 {  
 nw=alloc(p);  
 if(nw!=NULL)  
 {  
 t=p;  
 if(p==NULL)  
 {  
 p=nw;  
 nw->link=p;  
 }  
 else  
 {  
 do  
 {  
 if(nw==t)  
 {  
 if(nw==p)  
 p=0;  
 else  
 p=nw;  
 break;  
 }  
 t=t->link;  
 }while(t!=p);  
 if(p!=0&&p!=nw)  
 {  
 if(nw->pow>p->pow)  
 {  
 while(t->link!=p)  
 t=t->link;  
 nw->link=p;  
 p=nw;  
 t->link=p;  
 }  
 else  
 {  
 while(t->link!=p && nw->powlink->pow)  
 t=t->link;  
 nw->link=t->link;  
 t->link=nw;  
 }  
 }  
 }  
 }  
 printf("\nDO U WANT ENTER MORE:y/n");  
 }while(getche()=='y');  
 return p;  
 }  
 poly1 *alloc(poly1* p)  
 {  
 poly1 *nw,*t,*n,*t1;  
 t=p;  
 nw=(poly1 *)malloc(sizeof(poly1));  
 while(1)  
 {  
 printf("\nENTER COEFF:");  
 nw->coeff=validf();  
 if(nw->coeff!=0)  
 break;  
 }  
 printf("\nENTER POWER:");  
 nw->pow=valid();  
 if(p!=NULL)  
 do  
 {  
 if(nw->pow==t->link->pow)  
 {  
 printf("\nthis power already exits");  
 printf("DO U WANT TO ADD IT IN PREVEIOUS:y/n");  
 if(getche()=='y')  
 {  
 t->link->coeff=t->link->coeff+nw->coeff;  
 if(t->link->coeff==0)  
 {  
 n=t->link;  
 t->link=t->link->link;  
 if(p->coeff==0)  
 {  
 p=p->link;  
 free(n);  
 free(nw);  
 return p;  
 }  
 free(n);  
 }  
 }  
 free(nw);  
 return(NULL);  
 }  
 t=t->link;  
 }while(t!=p);  
 return nw;  
 } */  
 void display( poly1 *p)  
 {  
 poly1 *t;  
 t=p;  
 do  
 {  
 if(t->coeff==1)  
 {  
 if(t->pow==0)  
 printf("%f",t->coeff);  
 }  
 else  
 printf("%f",t->coeff);  
 if(t->pow!=0)  
 printf("x");  
 if(t->pow>1)  
 printf("^%d",t->pow);  
 t=t->link;  
 if(t!=p)  
 if(t->coeff>0)  
 printf("+");  
 }while(t!=p);  
 getch();  
 }  
 float evaluate(poly1 *p,float x)  
 {  
 float result=0;  
 poly1 *t;  
 t=p;  
 do  
 {  
 result+=(t->coeff * pow(x,t->pow) );  
 t=t->link;  
 } while(t!=p);  
 return result;  
 }  
 poly1 *add(poly1 *p1,poly1 *p2)  
 {  
 poly1 *p3,*t,*s,*r,*last;  
 int flag=0,flag1=0;  
 t=p1;  
 s=p2;  
 p3=NULL;  
 last=p3;  
 if(p1==NULL)  
 return p2;  
 if(p2==NULL)  
 return p1;  
 do  
 {  
 r=(poly1 *)malloc(sizeof(poly1));  
 if(t->powpow)  
 {  
 r->pow=s->pow;  
 r->coeff=s->coeff;  
 s=s->link;  
 flag1=1;  
 }  
 else if(t->pow>s->pow)  
 {  
 r->pow=t->pow;  
 r->coeff=t->coeff;  
 t=t->link;  
 flag=1;  
 }  
 else  
 {  
 r->pow=t->pow;  
 r->coeff=t->coeff+s->coeff;  
 s=s->link;  
 t=t->link;  
 flag=1;  
 flag1=1;  
 }  
 if(r->coeff!=0)  
 {  
 if(p3==NULL)  
 {  
 p3=r;  
 }  
 else  
 {  
 last->link=r;  
 }  
 last=r;  
 }  
 else  
 free(r);  
 }while((t!=p1||flag==0)&&(s!=p2||flag1==0));  
 while(t!=p1||flag==0)  
 {  
 if(p3==NULL)  
 {  
 p3=r=(poly1 *)malloc(sizeof(poly1));  
 }  
 else  
 {  
 r->link=(poly1 *)malloc(sizeof(poly1));  
 r=r->link;  
 }  
 r->pow=t->pow;  
 r->coeff=t->coeff;  
 t=t->link;  
 flag=1;  
 last=r;  
 }  
 while(s!=p2||flag1==0)  
 {  
 if(p3==NULL)  
 {  
 p3=r=(poly1 *)malloc(sizeof(poly1));  
 }  
 else  
 {  
 r->link=(poly1 *)malloc(sizeof(poly1));  
 r=r->link;  
 }  
 r->pow=s->pow;  
 r->coeff=s->coeff;  
 s=s->link;  
 flag1=1;  
 last=r;  
 }  
 last->link=p3;  
 return p3;  
 }  
 poly1 *mul(poly1 *p1,poly1 * p2)  
 {  
 poly1 *p,*t,*r,*s,*n;  
 t=p1;  
 s=p2;  
 p=NULL;  
 r=NULL;  
 do  
 {  
 do  
 {  
 r=(poly1 *)malloc(sizeof(poly1));  
 r->coeff=t->coeff*s->coeff;  
 r->pow=t->pow+s->pow;  
 n=p;  
 if(p==NULL)  
 {  
 p=r;  
 r->link=p;  
 }  
 else  
 {  
 while(n->link!=p && r->powlink->pow)  
 n=n->link;  
 if(r->pow==n->link->pow)  
 {  
 n->link->coeff=r->coeff+n->link->coeff;  
 free(r);  
 if(n->link->coeff==0)  
 {  
 r=n->link;  
 n->link=p;  
 free(r);  
 }  
 }  
 else  
 {  
 r->link=n->link;  
 n->link=r;  
 }  
 }  
 t=t->link;  
 }while(t!=p1);  
 s=s->link;  
 }while(s!=p2);  
 return p;  
 }  
 poly1 *freeall(poly1 *p)  
 {  
 poly1 *t,*r;  
 r=p;  
 do  
 {  
 t=r;  
 r=r->link;  
 free(t);  
 }while(r!=p);  
 return p;  
 }  
 int valid()  
 {  
 int k,p;  
 char str[25];  
 k=-1;  
 do  
 {  
 k++;  
 str[k]=getche();  
 if(k>0)  
 if(str[k]=='\r')  
 {  
 str[k]='\0';  
 return(atoi(str));  
 }  
 if(str[k]<48 || str[k]>57)  
 {  
 printf("\ninvalid choice");  
 k--;  
 }  
 }while(str[k]!='\r');  
 return(0);  
 }  
 float validf()  
 {  
 int k,p,count=0;  
 char str[25];  
 k=-1;  
 do  
 {  
 k++;  
 str[k]=getche();  
 if(k>0)  
 if(str[k]=='\r')  
 {  
 str[k]='\0';  
 return(atof(str));  
 }  
 if(str[k]==46||str[k]==45)  
 count++;  
 if(((str[k]<48||str[k]>57)&& (str[k]!=46&&str[k]!=45)) || count>1)  
 {  
 printf("\ninvalid choice");  
 count=0;  
 k--; }  
 }while(str[k]!='\r');  
 return(0);  
 }  
 poly1 *create()  
 {  
 poly1 *nw,*p,*t,*r,*s;  
 p=NULL;  
 do  
 {  
 nw=alloc();  
 if(nw!=NULL)  
 {  
 t=p;  
 if(p==NULL)  
 {  
 p=nw;  
 nw->link=p;  
 }  
 else  
 {  
 if(nw->pow>p->pow)  
 {  
 while(t->link!=p)  
 t=t->link;  
 nw->link=p;  
 p=nw;  
 t->link=p;  
 }  
 else  
 {  
 while(t->link!=p && nw->pow<=t->link->pow)  
 t=t->link;  
 if(nw->pow==t->pow)  
 {  
 printf("\nthis power already exits");  
 printf("DO U WANT TO ADD IT IN PREVEIOUS:y/n");  
 if(getche()=='y')  
 {  
 t->coeff+=nw->coeff;  
 if(t->coeff==0)  
 {  
 if(p==p->link)  
 {  
 free(p);  
 p=NULL;  
 }  
 else  
 {  
 r=p;  
 while(r->link!=t)  
 r=r->link;  
 s=t;  
 if(p==t)  
 {  
 p=t->link;  
 }  
 r->link=t->link;  
 free(s);  
 }  
 }  
 }  
 free(nw);  
 }  
 else  
 {  
 nw->link=t->link;  
 t->link=nw;  
 }  
 }  
 }  
 }  
 printf("\nDO U WANT ENTER MORE:y/n");  
 }while(getche()=='y');  
 return p;  
 }  
 poly1 *alloc()  
 {  
 poly1 *nw;  
 nw=(poly1 *)malloc(sizeof(poly1));  
 while(1)  
 {  
 printf("\nENTER COEFF:");  
 nw->coeff=validf();  
 if(nw->coeff!=0)  
 break;  
 }  
 printf("\nENTER POWER:");  
 nw->pow=valid();  
 return nw;  
 }

Other Projects to Try:

  1. Expression Tree using C Language
  2. Breadth First and Depth First Search C Language
  3. Single Link List code using C Language
  4. Double Link List code using C Langauge
  5. Hash table code in C Language

Filed Under: C Assignments, Datastructure and Files Tagged With: Datastructure Assignments

Sparse Matrix Operations Code using C Langauge

April 3, 2011 by ProjectsGeek Leave a Comment

Sparse Matrix Operations  in C

Represent Sparse Matrix using array and perform Matrix Addition, Simple and Fast Transpose.
Polynomial representation using array, Concept of Sparse Matrix, it’s usage & representation using arrays, Algorithms for sparse matrix operations like addition, simple transpose, fast transpose & multiplication
 

 #define max 50  
 #include  
 #include  
 int input(int as[][3]);  
 void display(int*,int,int);  
 void display1(int[][3]);  
 void sp(int *,int [][3],int,int);  
 void add(int[][3],int[][3],int[][3]);  
 void sub(int[][3],int[][3],int[][3]);  
 void trans(int [][3],int [][3]);  
 void ftrans(int[][3],int [][3]);  
 void mul(int[][3],int [][3],int[][3]);  
 void main()  
 {  
 int as[max][3],bs[max][3],r[max][3],ch,ch1;  
 as[0][2]=0;  
 bs[0][2]=0 ;  
 do  
 {  
 clrscr();  
 printf("Enter your choice to performe sparse matrix menuplation");  
 printf("\n1.Input matrix\n2.Display Sparse matrix");  
 printf("\n3.Addition of two sparse matrix\n");  
 printf("4.Subtraction of two sparse matrix");  
 printf("\n5.Multiplecation of two sparse matrix");  
 printf("\n6.Transpose of matrix\n7.Fast transpose of matrix");  
 printf("\n8.Exit");  
 scanf("%d",&ch);  
 switch(ch)  
 {  
 case 1:  
 do  
 {  
 clrscr();  
 printf("\nEnter your choice\n");  
 printf("1.Matrix 1\n2.Matrix 2\n3.return");  
 scanf("%d",&ch1);  
 switch(ch1)  
 {  
 case 1 :  
 clrscr();  
 input(as);  
 break;  
 case 2 :  
 clrscr();  
 input(bs);  
 break;  
 case 3:  
 break;  
 default:  
 printf("\nInvalid choice\n");  
 getch();  
 }  
 }while(ch1!=3);  
 break;  
 case 2:  
 do  
 {  
 clrscr();  
 printf("\nEnter your choice to display\n");  
 printf("1.Matrix 1\n2.Matrix 2\n3.return");  
 scanf("%d",&ch1);  
 switch(ch1)  
 {  
 case 1 :  
 clrscr();  
 if(as[0][2]==0)  
 {  
 printf("First enter the matrix1\n");  
 getch();  
 }  
 else  
 {  
 printf("Sparse matrix 1=\n");  
 display1(as);  
 getch();  
 }  
 break;  
 case 2 :  
 clrscr();  
 if(bs[0][2]==0)  
 {  
 printf("First enter the matrix2\n");  
 getch();  
 }  
 else  
 {  
 printf("Sparse matrix 2=\n");  
 display1(bs);  
 getch();  
 }  
 break;  
 case 3:  
 break;  
 default:  
 printf("\nInvalid choice\n");  
 getch();  
 }  
 }while(ch1!=3);  
 break;  
 case 3:  
 clrscr();  
 if(as[0][2]==0||bs[0][2]==0)  
 {  
 printf("First enter both matrices\n");  
 getch();  
 }  
 else  
 {  
 printf("SPARSE MATRIX A-\n");  
 display1(as);  
 printf("SPARSE MATRIX B-\n");  
 display1(bs);  
 add(as,bs,r);  
 printf("\nSPARSE ADDITION OF TWO MATRIX-\n");  
 display1(r);  
 getch();  
 }  
 break;  
 case 4:  
 do  
 {  
 clrscr();  
 printf("\nEnter your choice to Sparse subtraction");  
 printf("\n1.MAT A- MAT B\n2.MAT B-MAT A\n3.RETURN");  
 scanf("%d",&ch1);  
 switch(ch1)  
 {  
 case 1:  
 clrscr();  
 if(as[0][2]==0||bs[0][2]==0)  
 {  
 printf("First enter both matrices\n");  
 getch();  
 }  
 else  
 {  
 printf("SPARSE MATRIX A-\n");  
 display1(as);  
 printf("SPARSE MATRIX B-\n");  
 display1(bs);  
 sub(as,bs,r);  
 printf("\nSPARSE SUBTRACTION OF TWO MATRIX-\n");  
 display1(r);  
 getch();  
 }  
 break;  
 case 2:  
 clrscr();  
 if(as[0][2]==0||bs[0][2]==0)  
 {  
 printf("First enter both matrices\n");  
 getch();  
 }  
 else  
 {  
 printf("SPARSE MATRIX A-\n");  
 display1(as);  
 printf("SPARSE MATRIX B-\n");  
 display1(bs);  
 sub(bs,as,r);  
 printf("\nSPARSE SUBTRACTION OF TWO MATRIX-\n");  
 display1(r);  
 getch();  
 }  
 break;  
 case 3:  
 break;  
 }  
 }while(ch1!=3);  
 break;  
 case 5:  
 do  
 {  
 clrscr();  
 printf("\nEnter your choice to Sparse subtraction");  
 printf("\n1.MAT A* MAT B\n2.MAT B*MAT A\n3.RETURN");  
 scanf("%d",&ch1);  
 switch(ch1)  
 {  
 case 1:  
 clrscr();  
 if(as[0][2]==0||bs[0][2]==0)  
 {  
 printf("First enter both matrices\n");  
 getch();  
 }  
 else  
 {  
 printf("SPARSE MATRIX A-\n");  
 display1(as);  
 printf("SPARSE MATRIX B-\n");  
 display1(bs);  
 mul(as,bs,r);  
 printf("\nSPARSE MULTIPLECATION OF TWO MATRIX-\n");  
 display1(r);  
 getch();  
 }  
 break;  
 case 2:  
 clrscr();  
 if(as[0][2]==0||bs[0][2]==0)  
 {  
 printf("First enter both matrices\n");  
 getch();  
 }  
 else  
 {  
 printf("SPARSE MATRIX A-\n");  
 display1(as);  
 printf("SPARSE MATRIX B-\n");  
 display1(bs);  
 mul(bs,as,r);  
 printf("\nSPARSE MULTIPLECATION OF TWO MATRIX-\n");  
 display1(r);  
 getch();  
 }  
 break;  
 case 3:  
 break;  
 }  
 }while(ch1!=3);  
 break;  
 case 6:  
 do  
 {  
 clrscr();  
 printf("\nEnter your choice to Sparse Simple transpose");  
 printf("\n1.MAT A\n2.MAT B\n3.RETURN");  
 scanf("%d",&ch1);  
 switch(ch1)  
 {  
 case 1:  
 clrscr();  
 if(as[0][2]==0)  
 {  
 printf("First enter the matrix1\n");  
 getch();  
 }  
 else  
 {  
 printf("SPARSE MATRIX A-\n");  
 display1(as);  
 trans(as,r);  
 printf("\nSPARSE SIMPLE TRANSPOSE OF TWO MATRIX-\n");  
 display1(r);  
 getch();  
 }  
 break;  
 case 2:  
 clrscr();  
 if(bs[0][2]==0)  
 {  
 printf("First enter the matrix2\n");  
 getch();  
 }  
 else  
 {  
 printf("SPARSE MATRIX B-\n");  
 display1(bs);  
 trans(bs,r);  
 printf("\nSPARSE SIMPLE TRANSPOSE OF TWO MATRIX-\n");  
 display1(r);  
 getch();  
 }  
 break;  
 case 3:  
 break;  
 }  
 }while(ch1!=3);  
 break;  
 case 7:  
 clrscr();  
 do  
 {  
 clrscr();  
 printf("\nEnter your choice to Sparse Fast transpose");  
 printf("\n1.MAT A\n2.MAT B\n3.RETURN");  
 scanf("%d",&ch1);  
 switch(ch1)  
 {  
 case 1:  
 clrscr();  
 if(as[0][2]==0)  
 {  
 printf("First enter the matrix1\n");  
 getch();  
 }  
 else  
 {  
 printf("SPARSE MATRIX A-\n");  
 display1(as);  
 ftrans(as,r);  
 printf("\nSPARSE FAST TRANSPOSE OF MATRIX A-\n");  
 display1(r);  
 getch();  
 }  
 break;  
 case 2:  
 clrscr();  
 if(bs[0][2]==0)  
 {  
 printf("First enter the matrix2\n");  
 getch();  
 }  
 else  
 {  
 printf("SPARSE MATRIX B-\n");  
 display1(bs);  
 ftrans(bs,r);  
 printf("\nSPARSE FAST TRANSPOSE OF MATRIX B-\n");  
 display1(r);  
 getch();  
 }  
 break;  
 case 3:  
 break;  
 }  
 }while(ch1!=3);  
 break;  
 case 8:  
 break;  
 default:  
 printf("\nINVALID CHOICE");  
 getch();  
 }  
 }while(ch!=8);  
 getch();  
 }  
 int input(int as[][3])  
 {  
 int *mat,*r,*c,i,j,n1;  
 printf("Enter no. of rows <50:\n");  
 scanf("%d",r);  
 printf("Enter no. of colums <50:\n");  
 scanf("%d",c);  
 if(*r>max || *c>max)  
 {  
 printf("Error : \nSize of matrix is not is range.");  
 getch();  
 return(0);  
 }  
 else  
 {  
 mat=(int*)calloc(*r,(*c)*(sizeof(int)));  
 printf("Enter elements of matrix \n");  
 for(i=0;i<*r;i++)  
 {  
 for(j=0;j<*c;j++)  
 {  
 scanf("%d",(mat+(i*(*c))+j));  
 }  
 }  
 }  
 printf("Matrix is -\n");  
 display(mat,*r,*c);  
 printf("\nSparse form of matrix is-\n");  
 sp(mat,as,*r,*c);  
 free(mat);  
 display1(as);  
 printf("\n");  
 getch();  
 return(0);  
 }  
 void display(int *mat,int r,int c)  
 {  
 int i,j;  
 for(i=0;i<r;i++) <br=""> {  
 for(j=0;j<c;j++) <br=""> {  
 printf("%d\t",*(mat+(i*c)+j));  
 }  
 printf("\n");  
 }  
 }  
 void sp(int *mat,int as[][3], int r,int c)  
 {  
 int i,j,n=0;  
 as[0][0]=r;  
 as[0][1]=c;  
 for(i=0;i<r;i++) <br=""> {  
 for(j=0;j<c;j++) <br=""> {  
 if(*(mat+(i*c)+j)!=0)  
 {  
 n++;  
 as[n][0]=i;  
 as[n][1]=j;  
 as[n][2]=*(mat+(i*c)+j);  
 }  
 }  
 }  
 as[0][2]=n;  
 }  
 void display1(int mat[][3])  
 {  
 int i;  
 for(i=0;i<=mat[0][2];i++)  
 printf("%d\t%d\t%d\n",mat[i][0],mat[i][1],mat[i][2]);  
 }  
 void add(int as[][3],int bs[][3],int r[][3])  
 {  
 int i=1,j=1,k=1;  
 if(as[0][0]!=bs[0][0] || as[0][1]!=bs[0][1])  
 {  
 printf("\nRank of matrices is not Suitable");  
 return;  
 }  
 else  
 {  
 r[0][0]=as[0][0];  
 r[0][1]=as[0][1];  
 while(i<=as[0][2] && j<=bs[0][2])  
 {  
 if(as[i][0]==bs[j][0] && as[i][1]==bs[j][1])  
 {  
 r[k][2]=as[i][2]+bs[j][2];  
 if(r[k][2]!=0)  
 {  
 r[k][0]=as[i][0];  
 r[k][1]=as[i][1];  
 k++;  
 }  
 j++;i++;  
 }  
 else  
 {  
 if(as[i][0]<bs[j][0]) <br=""> {  
 r[k][0]=as[i][0];  
 r[k][1]=as[i][1];  
 r[k][2]=as[i][2];  
 i++;k++;  
 }  
 else  
 {  
 if(as[i][0]==bs[j][0])  
 {  
 if(as[i][1]<bs[j][1]) <br=""> {  
 r[k][0]=as[i][0];  
 r[k][1]=as[i][1];  
 r[k][2]=as[i][2];  
 i++;k++;  
 }  
 else  
 {  
 r[k][0]=bs[j][0];  
 r[k][1]=bs[j][1];  
 r[k][2]=bs[j][2];  
 j++;k++;  
 }  
 }  
 else  
 {  
 r[k][0]=bs[j][0];  
 r[k][1]=bs[j][1];  
 r[k][2]=bs[j][2];  
 j++;k++;  
 }  
 }  
 }  
 }  
 while(i<=as[0][2])  
 {  
 r[k][0]=as[i][0];  
 r[k][1]=as[i][1];  
 r[k][2]=as[i][2];  
 i++;k++;  
 }  
 while(j<=bs[0][2])  
 {  
 r[k][0]=bs[j][0];  
 r[k][1]=bs[j][1];  
 r[k][2]=bs[j][2];  
 j++;k++;  
 }  
 }  
 r[0][2]=k-1;  
 }  
 void sub(int as[][3],int bs[][3],int r[][3])  
 {  
 int i=1,j=1,k=1;  
 if(as[0][0]!=bs[0][0] || as[0][1]!=bs[0][1])  
 {  
 printf("\nRank of matrices is not Suitable");  
 return;  
 }  
 else  
 {  
 r[0][0]=as[0][0];  
 r[0][1]=as[0][1];  
 while(i<=as[0][2] && j<=bs[0][2])  
 {  
 if(as[i][0]==bs[j][0] && as[i][1]==bs[j][1])  
 {  
 r[k][2]=as[i][2]-bs[j][2];  
 if(r[k][2]!=0)  
 {  
 r[k][0]=as[i][0];  
 r[k][1]=as[i][1];  
 k++;  
 }  
 j++;i++;  
 }  
 else  
 {  
 if(as[i][0]<bs[j][0]) <br=""> {  
 r[k][0]=as[i][0];  
 r[k][1]=as[i][1];  
 r[k][2]=as[i][2];  
 i++;k++;  
 }  
 else  
 {  
 if(as[i][0]==bs[j][0])  
 {  
 if(as[i][1]<bs[j][1]) <br=""> {  
 r[k][0]=as[i][0];  
 r[k][1]=as[i][1];  
 r[k][2]=as[i][2];  
 i++;k++;  
 }  
 else  
 {  
 r[k][0]=bs[j][0];  
 r[k][1]=bs[j][1];  
 r[k][2]=-bs[j][2];  
 j++;k++;  
 }  
 }  
 else  
 {  
 r[k][0]=bs[j][0];  
 r[k][1]=bs[j][1];  
 r[k][2]=-bs[j][2];  
 j++;k++;  
 }  
 }  
 }  
 }  
 while(i<=as[0][2])  
 {  
 r[k][0]=as[i][0];  
 r[k][1]=as[i][1];  
 r[k][2]=as[i][2];  
 i++;k++;  
 }  
 while(j<=bs[0][2])  
 {  
 r[k][0]=bs[j][0];  
 r[k][1]=bs[j][1];  
 r[k][2]=-bs[j][2];  
 j++;k++;  
 }  
 }  
 r[0][2]=k-1;  
 }  
 void trans(int as[][3],int r[][3])  
 {  
 int i,j,k=1;  
 r[0][0]=as[0][1];  
 r[0][1]=as[0][0];  
 r[0][2]=as[0][2];  
 for(i=0;i<as[0][1];i++) <br=""> {  
 for(j=1;j<=as[0][2];j++)  
 {  
 if(as[j][1]==i)  
 {  
 r[k][0]=as[j][1];  
 r[k][1]=as[j][0];  
 r[k][2]=as[j][2];  
 k++;  
 }  
 }  
 }  
 }  
 void ftrans(int as[][3],int r[][3])  
 {  
 int i,j,count[max],pos[max],rp;  
 r[0][0]=as[0][1];  
 r[0][1]=as[0][0];  
 r[0][2]=as[0][2];  
 for(i=0;i<as[0][1];i++) <br=""> count[i]=0;  
 for(i=1;i<=as[i][2];i++)  
 count[as[i][1]]++;  
 pos[0]=1;  
 for(i=0;i<(as[0][1]-1);i++)  
 pos[i+1]=pos[i]+count[i];  
 for(i=1;i<=as[0][2];i++)  
 {  
 rp=pos[as[i][1]]++;  
 r[rp][0]=as[i][1];  
 r[rp][1]=as[i][0];  
 r[rp][2]=as[i][2];  
 }  
 }  
 void mul(int as[][3],int bs[][3],int r[][3])  
 {  
 int i,j,*t;  
 t=(int*)calloc(as[0][0],(bs[0][1])*(sizeof(int)));  
 if(as[0][1]==bs[0][0])  
 {  
 for(i=1;i<=as[0][2];i++)  
 {  
 for(j=1;j<=bs[0][2];j++)  
 {  
 if(as[i][1]==bs[j][0])  
 {  
 *(t+(as[i][0]*bs[0][1])+bs[j][1])+=as[i][2]*bs[j][2];  
 }  
 }  
 }  
 }  
 else  
 printf("\nYOUR MATRICES ARE NOT SUITABLE FOR MULTIPLECTION");  
 sp(t,r,as[0][0],bs[0][1]);  
 free(t);  
 }

 

Other Projects to Try:

  1. Matrix operations in c language
  2. Matrix Operations in C Language
  3. Matrix Operations with Pointers
  4. Operations on matrices like addition, multiplication, saddle point, magic square ,inverse & transpose
  5. Hash table code in C Language

Filed Under: C Assignments, Fundamentals of Datastructure Tagged With: Datastructure Assignments

  • « Go to Previous Page
  • Page 1
  • Page 2
  • Page 3
  • Page 4

Primary Sidebar

Tags

.Net Projects Download Android Project Ideas Android Projects Angular 2 Assembly Codes C # Projects C & C++ Projects C++ Projects Class Diagrams Computer Graphics Database Project Data Mining Projects DataScience Projects Datastructure Assignments Download Visual Basic Projects Electronics project Hadoop Projects Installation Guides Internet of Things Project IOS Projects Java Java Interview Questions Java Projects JavaScript JavaScript Projects java tutorial JSON JSP Projects Mechanical Projects Mongodb Networking Projects Node JS Projects OS Problems php Projects Placement Papers Project Ideas Python Projects seminar and presentation Struts

Search this Website


Footer

Download Java Project
Download Visual Basic Projects
Download .Net Projects
Download VB Projects
Download C++ Projects
Download NodeJs Projects
Download School Projects
Download School Projects
Ask Questions - Forum
Latest Projects Ideas
Assembly Codes
Datastructure Assignments
Computer Graphics Lab
Operating system Lab
australia-and-India-flag
  • Home
  • About me
  • Contact Form
  • Submit Your Work
  • Site Map
  • Privacy Policy