728x90 AdSpace

Latest Article

C C++ Program code function for matrix addition and multiplication





Assignment or home work C C++ write  Program code function for  matrix addition and multiplication in C C++ Programming Language implementation

#include<stdio.h>
#include<conio.h>

#include<process.h>
void operation(int *(*matrix1),char op,int *(*matrix2),int,int);
void print(int,int,int,int);
void main()
{
clrscr();
char op;
int rows,columns,row,col;
int *(*matrix1),*(*matrix2),*(*matrix3)={0};
printf("plz, enter the no. of rows & columns:");
scanf("%d %d",&rows,&columns);
for(row=0;row<rows;row++)
     {
      *(matrix1+row)=(int *) malloc(columns*sizeof(int));
      *(matrix2+row)=(int *) malloc(columns*sizeof(int));
      *(matrix3+row)=(int *) malloc(columns*sizeof(int));
      }
       print(rows,columns,5,5);
       for(row=0;row<rows;row++)
  for(col=0;col<columns;col++)
    {
    gotoxy(6+col+8*col,6+row);
    scanf("%d",*(matrix1+row)+col);
    }
       gotoxy(8+col+8*col,5+row);
       op=getche();
       print(rows,columns,30,5);
for(row=0;row<rows;row++)
  for(col=0;col<columns;col++)
    {
    gotoxy(32+col+8*col,6+row);
    scanf("%d",*(matrix2+row)+col);
    }
operation(matrix1,op,matrix2,rows,columns);

getch();
}
///////// function   for   matrix addition and multiplication/////////////
void operation(int *(*matrix1),char op,int *(*matrix2),int rows,int columns)
{
int row,col,count;
int *(*matrix3)={0};
switch(op)
{
case '+':
for(row=0;row<rows;row++)
for(col=0;col<columns;col++);
      *(*(matrix3+row)+col)=(*(*(matrix1+row)+col))+(*(*(matrix2+row)+col));
break;
case '*':
for(row=0;row<rows;row++)
for(col=0;col<columns;col++)
for(count=0;count<columns;count++)
*(*(matrix3+row)+col)=(*(*(matrix1+col)+count))+(*(*(matrix2+count)+col))+(*(*(matrix3+row)+col));
break;
default:
printf("no solution");
exit(0);
getch();
}
gotoxy(50,6);
printf("=");
print(rows,columns,60,5);
for(row=0;row<rows;row++)
  for(col=0;col<columns;col++)
    {
    gotoxy(61+col+8*col,6+row);
    printf("%d",*(*(matrix3+row)+col));
    }
}
 //// function for matrix print ///////////////////////////////////////
void print(int rows,int columns,int x,int y)
{
int row,col;
gotoxy(x,y);
printf("%c",218);
gotoxy(x+columns*7,y);
printf("%c",191);
for(row=0;row<=rows;row++)
for(col=0;col<columns;col++)
if(col==0)
{
gotoxy(x,y+1+row);
printf("%c",179);
}
else if(col==columns-1)
{
gotoxy(x+columns*7,y+1+row);
printf("%c",179);
}
gotoxy(x,y+1+rows);
printf("%c",192);
gotoxy(x+columns*7,y+1+rows);
printf("%c",217);
}





no image
  • Title : C C++ Program code function for matrix addition and multiplication
  • Posted by :
  • Date : 04:05
  • Labels :





  • Blogger Comments
  • Facebook Comments

0 comments:

Post a Comment

Top