Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 37

Thread: Program to do matrices

  1. #21
    Join Date
    Sep 2003
    Posts
    603
    Rep Power
    0

    Default

    Quote Originally Posted by crosswire
    Alright boss.

    Any language will suffice, except designing your own language. Mi no so skilled. Mi wi train fi you then

    PS nuclear is so last century, it has reached its pinnacle
    I am just some guy who thinks he is better than he is, I can be so arrogant sometimes...but I like your style. the first comment you made on this thread made perfect sense.. you cant start coding before you design...BIG TROUBLE. my problem is I like to code but not design... half way through I get fustrated because of the issues which pops up when you dont design well.. lately I have been forcing myself to design twice code once...
    easiparcel.com Shop online and ship to Jamaica

  2. #22
    Join Date
    Dec 2004
    Posts
    476
    Rep Power
    0

    Default

    hmm you did it in c++ and it works but this is what im getting in c
    -------------------Configuration: project - Win32 Debug--------------------
    Compiling...
    project.c
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(230) : warning C4013: 'multiplication' undefined; assuming extern returning int
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(406) : error C2371: 'multiplication' : redefinition; different basic types
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(406) : error C2085: '_M1ROWS' : not in formal parameter list
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(406) : error C2143: syntax error : missing ';' before '='
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(412) : error C2371: 'main' : redefinition; different basic types
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(27) : see declaration of 'main'
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(414) : error C2065: '_M1ROWS' : undeclared identifier
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(414) : error C2057: expected constant expression
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(414) : error C2466: cannot allocate an array of constant size 0
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(414) : error C2065: '_M1COLS' : undeclared identifier
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(414) : error C2057: expected constant expression
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(414) : error C2466: cannot allocate an array of constant size 0
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(414) : error C2087: '<Unknown>' : missing subscript
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(417) : error C2143: syntax error : missing ';' before '/'
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(423) : error C2143: syntax error : missing ';' before 'type'
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(425) : error C2143: syntax error : missing ';' before '/'
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(429) : error C2065: 'rowM1' : undeclared identifier
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(432) : error C2065: 'colM2' : undeclared identifier
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(432) : error C2065: '_M2COLS' : undeclared identifier
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(436) : error C2065: 'rowColIndx' : undeclared identifier
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(438) : error C2065: 'Matrix2' : undeclared identifier
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(438) : error C2109: subscript requires array or pointer type
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(438) : error C2109: subscript requires array or pointer type
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(440) : error C2065: 'rMatrix' : undeclared identifier
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(440) : error C2109: subscript requires array or pointer type
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(440) : error C2109: subscript requires array or pointer type
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(440) : error C2106: '=' : left operand must be l-value
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(444) : error C2109: subscript requires array or pointer type
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(444) : error C2109: subscript requires array or pointer type
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(445) : error C2109: subscript requires array or pointer type
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(445) : error C2109: subscript requires array or pointer type
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(446) : error C2109: subscript requires array or pointer type
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(446) : error C2109: subscript requires array or pointer type
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(447) : error C2109: subscript requires array or pointer type
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(447) : error C2109: subscript requires array or pointer type
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(449) : error C2143: syntax error : missing ';' before 'type'
    Error executing cl.exe.

    project.obj - 34 error(s), 1 warning(s)

    now thats a lot of errors considering im coming from zero.
    WHY PAY WHEN YOU CAN GET IT FREE!!!!!

  3. #23
    Join Date
    Sep 2004
    Posts
    1,905
    Rep Power
    21

    Default

    'multiplication' ??
    C:\Documents and Settings\Perferred Customer\My Documents\project.c(230) : warning C4013: 'multiplication' undefined; assuming extern returning int
    Post the entire code
    Let's act on what we agree on now, and argue later on what we don't.
    Black men leave Barbeque alone if Barbeque don't trouble you

  4. #24
    Join Date
    Sep 2004
    Posts
    1,905
    Rep Power
    21

    Default

    Quote Originally Posted by CGPGroup
    I am just some guy who thinks he is better than he is, I can be so arrogant sometimes...but I like your style. the first comment you made on this thread made perfect sense.. you cant start coding before you design...BIG TROUBLE. my problem is I like to code but not design... half way through I get fustrated because of the issues which pops up when you dont design well.. lately I have been forcing myself to design twice code once...
    I second that with design.

    Truth is it was icymint who first suggested that, not me.

    Design can take weeks! and not even a touch of code, especially for designing a system to handle tasks with alot of possiblities, furthermore in unfamiliar system models.
    Let's act on what we agree on now, and argue later on what we don't.
    Black men leave Barbeque alone if Barbeque don't trouble you

  5. #25
    Join Date
    Sep 2004
    Posts
    1,905
    Rep Power
    21

    Default

    To add, it is also better to code sometimes and find out the problems which are often hard to figure out otherwise, then fix the problems.

    I am lazy at doing that, almost as much as designing.

    PS: Mean no offence in my tone
    Let's act on what we agree on now, and argue later on what we don't.
    Black men leave Barbeque alone if Barbeque don't trouble you

  6. #26
    Join Date
    Dec 2004
    Posts
    476
    Rep Power
    0

    Default

    ok, this is the code that i have let me give you the requirements for the program
    1. should be able to populate a maximum of three matrices. limit size of the matrix is 5 rows 5 coloumns. use arrays to store the matrices
    2. program should be able to do scalar multiplication, addition of a pair of matrices, subtraction of a pair of matrices and multiplication of a pair of matrices.
    3.a matrix acn only be displayed if it was populated
    4.use a modular design
    5. allow the program to have a menu driven interface
    ok this is what i have i know couple parts may be wrong so plz help me out.
    Code:
    #include<stdio.h>
    #include<stdlib.h>
    #include<conio.h>
    #include<math.h>
    #include<ctype.h>
    
    
    # define ROW_MAX 5
    # define Column_MAX 5
    
    int rows=0,size=0;
    int columns =0;
    int arrayA[ROW_MAX][Column_MAX];
    int arrayB[ROW_MAX][Column_MAX];
    int arrayC[ROW_MAX][Column_MAX];
    
    
    void display(void);
    void Populate_Matrix(void);
    void Main_menu(void);
    void operations();
    void addition();
    void subtraction();
    void ScalarMult();
    
    
    void main()
    {// start of main
    
    Main_menu();
    
    }//end of main
    
    
    void Main_menu(void)
    {
    	char choice;
    	do
    	{
    
    	printf("\tA.   Populate the matrix\n");
    	printf("\tB.   Display the matrix\n");
    	printf("\tC.   Perform operation\n");
    	printf("\tD.   Credits\n");
    	printf("\tE.   Exit Program\n\n\n");
    	printf("Please enter your choice: ");
    	scanf(" %c",&choice);
    	choice = toupper(choice);
        //system("cls");
    
    	switch(choice)
    	{
    	case 'A':{  
    				 Populate_Matrix();
    				break;
    			 }
    
    	case 'B':
    
    		{
    			display();
    			break;
    		}
    
    	case 'C':
    	
    		{
    			operations();
    
    			break;
    		}
    
    	case 'D':
    
    		{
    			printf("done by Akeem Gordon CMCS 0506476\n\n\n\n");
    			break;
    		}
    
    	case 'E':
    		{
    			break;
    		}
    
        default:
    		{
    		printf("Please choose a letter from A-E,You enterd a letter that is not accepted\n");
    		}
    	}
    	}while(choice !=0);
    }
    
    void Populate_Matrix(void)
    {
    	 
    	 int  i,j;
    
    	do
    	{
    
    	 printf("Enter the number of matrix you need\n");
    	 scanf("%d",&size);
    
    	}while(size <0 || size >5);
    
    	 printf("Enter the number of row and colums of mantrix\n");
    	
    	 scanf("%d%d",&rows,&columns);
    
    
    	if(size > 0 && size <= 5 )
    	{
      	 printf("\tA.   Add values to matrix A\n");
    		for(i=0; i < rows; i++)
    		{
    			for(j=0;j < columns; j++)
    			{
    				scanf("%d",&arrayA[i][j]);
    			}
    		}
    	}
    
    	
    	if(size>1 && size <=5)
    	{
      	 printf("\tA.   Add values to matrix B\n");
    		for(i=0; i < rows; i++)
    		{
    			for(j=0;j < columns; j++)
    			{
    				scanf("%d",&arrayB[i][j]);
    			}
    		}
    	}
    
    	
    	if(size>2 && size <=5)
    	{
      	 printf("\tA.   Add values to matrix C\n");
    		for(i=0; i < rows; i++)
    		{
    			for(j=0;j < columns; j++)
    			{
    				scanf("%d",&arrayC[i][j]);
    			}
    		}
    	}
    	
    	
    
    }
    
    
    void display(void)
    {
    	int i, j;
    	
    	if(size > 0 && size <= 5 )
    	{
      	 printf("\t  Add values to matrix A\n");
    		for(i=0; i < rows; i++)
    		{
    			for(j=0;j < columns; j++)
    			{
    				printf("%d ",arrayA[i][j]);
    			}
    				printf("\n");
    		}
    	}
    	printf("\n");
    	
    	if(size>1 && size <=5)
    	{
      	 printf("\t  values to matrix B\n");
    		for(i=0; i < rows; i++)
    		{
    			for(j=0;j < columns; j++)
    			{
    					printf("%d ",arrayB[i][j]);
    			}
    			printf("\n");
    		}
    	}
    	printf("\n");
    	
    	if(size>2 && size <=5)
    	{
      	 printf("\tValues stores matrix C\n");
    		for(i=0; i < rows; i++)
    		{
    			for(j=0;j < columns; j++)
    			{
    					printf("%d ",arrayC[i][j]);
    			}
    				printf("\n");
    		}
    	}
    		printf("\n");
    
    
    }
    
    void operations()
    {
    	int choice=0;
    
    	do
    	{
    
    	printf("\t1	  Scalar\n");
    	printf("\t2   Addition\n");
    	printf("\t3   Substraction\n");
    	printf("\t4   Multiplication\n");
    	printf("\t5   Exit Program\n\n\n");
    	
    	scanf(" %d",&choice);
    	
    		switch(choice)
    		{
    				case 1: ScalarMult();
    
    					break;
    				case 2:addition();
    
    					break;
    				case 3:subtraction();
    
    					break;
    				
    				case 4:multiplication();
    
    					break;
    				
    				
    				
    				default:
    					{
    					printf("Please choose a letter from A-E,You enterd a letter that is not accepted\n");
    					}
    		}
    	}while(choice !=0);
    
    
    }
    
    void addition()
    {
    	int i,j;
    	int result[5][5]={0};
    	int choice1, choice2;
    
    	printf("Enter the two matrix you need to use\n");
    	scanf("%d %d", &choice1,&choice2);
    
    	if(choice1 == 1 && choice2 ==2)
    	{
    		for(i=0; i < rows; i++)
    		{
    			for(j=0;j < columns; j++)
    			{
    					printf("%d ",result[i][j] = arrayA[i][j] + arrayB[i][j]);
    			}
    			printf("\n");
    				
    		}
    	}
    
    		
    
    	
    	if(choice1 == 1 && choice2 ==3)
    	{
    		for(i=0; i < rows; i++)
    		{
    			for(j=0;j < columns; j++)
    			{
    				printf("%d ",result[i][j] = arrayA[i][j] + arrayC[i][j]);
    			}
    			printf("\n");
    				
    		}
    	}
    
    
    	if(choice1 == 2 && choice2 ==3)
    	{	
    		for(i=0; i < rows; i++)
    		{
    			for(j=0;j < columns; j++)
    			{
    				result[i][j] = arrayC[i][j] + arrayB[i][j];
    			}
    				
    		}
    	}
    	
    }
    
    void subtraction()
    {
    	int i,j;
    	int result[5][5]={0};
    	int choice1, choice2;
    
    	printf("Enter the two matrix you need to use\n");
    	scanf("%d %d", &choice1,&choice2);
    
    	if(choice1 == 1 && choice2 ==2)
    	{
    		for(i=0; i < rows; i++)
    		{
    			for(j=0;j < columns; j++)
    			{
    					printf("%d ",result[i][j] = arrayA[i][j] - arrayB[i][j]);
    			}
    			printf("\n");
    				
    		}
    	}
    
    		
    
    	
    	if(choice1 == 1 && choice2 ==3)
    	{
    		for(i=0; i < rows; i++)
    		{
    			for(j=0;j < columns; j++)
    			{
    				printf("%d ",result[i][j] = arrayA[i][j] - arrayC[i][j]);
    			}
    			printf("\n");
    				
    		}
    	}
    
    
    	if(choice1 == 2 && choice2 ==3)
    	{	
    		for(i=0; i < rows; i++)
    		{
    			for(j=0;j < columns; j++)
    			{
    				result[i][j] = arrayC[i][j] - arrayB[i][j];
    			}
    				
    		}
    	}
    
    }
    
    
    
    void ScalarMult()
    {
    	int i,j;
    	int result[5][5]={0};
    	int choice1, scaleFactor;
    
    	printf("Enter the two matrix you need to SCALE  and scale factor\n");
    	scanf("%d %d", &choice1,&scaleFactor);
    
    	if(choice1 == 1 )
    	{
    		for(i=0; i < rows; i++)
    		{
    			for(j=0;j < columns; j++)
    			{
    					printf("%d ",arrayA[i][j] * scaleFactor);
    			}
    			printf("\n");
    				
    		}
    	}
    
    		
    	if(choice1 == 2 )
    	{
    		for(i=0; i < rows; i++)
    		{
    			for(j=0;j < columns; j++)
    			{
    				printf("%d ",arrayB[i][j] * scaleFactor);
    			}
    			printf("\n");
    				
    		}
    	}
    
    
    	if(choice1 == 3)
    	{	
    		for(i=0; i < rows; i++)
    		{
    			for(j=0;j < columns; j++)
    			{
    					printf("%d ",arrayC[i][j] * scaleFactor);
    			}
    				
    		}
    	}
    
    }
    
    void multiplication()
    const int _M1ROWS = 2;
    const int _M1COLS = 3;
    const int _M2ROWS = 3;
    const int _M2COLS = 2;
    
    int main()
    {
    	
    	int Matrix1[_M1ROWS][_M1COLS] = {1,2,3,
    					 4,5,6};
    
    	/
    	int Matrix2[_M2ROWS][_M2COLS] = {1,2,
    					 3,4,
    					 5,6};
    
    	
    	int rMatrix [_M1ROWS][_M2COLS];
    
    	/
    	int rowM1, rowColIndx, colM2;
    
    	
    	for(rowM1=0;rowM1<_M1ROWS;rowM1++)
    	{
    		
    		for(colM2=0;colM2<_M2COLS;colM2++)
    		{
    			
    			int calResult = 0;
    			for(rowColIndx=0;rowColIndx<_M1COLS;rowColIndx++)
    			{
    				calResult = calResult +(Matrix1[rowM1][rowColIndx] * Matrix2[rowColIndx][colM2]);
    			}
    			rMatrix[rowM1][colM2]=calResult;
    		}
    	}
    
    printf("%d,",rMatrix[0][0]);
    printf("%d\n",rMatrix[0][1]);
    printf("%d,",rMatrix[1][0]);
    printf("%d",rMatrix[1][1]);
    
    int x;
    scanf("%d");
    }
    WHY PAY WHEN YOU CAN GET IT FREE!!!!!

  7. #27
    Join Date
    Sep 2003
    Posts
    603
    Rep Power
    0

    Default

    for the heck of it I am going to write the entire program, donate $4.99 to my paypal account and I will give you the entire code later...
    easiparcel.com Shop online and ship to Jamaica

  8. #28
    Join Date
    Dec 2004
    Posts
    476
    Rep Power
    0

    Default

    man im a college student struggling through school i dont even have a cent to spare. I dont really need the entire code just need the function for the operations.
    WHY PAY WHEN YOU CAN GET IT FREE!!!!!

  9. #29
    Join Date
    Sep 2003
    Posts
    603
    Rep Power
    0

    Default

    Quote Originally Posted by akoo
    man im a college student struggling through school i dont even have a cent to spare. I dont really need the entire code just need the function for the operations.
    dude I am just messing with your head.. did you get the multiplication to work?
    easiparcel.com Shop online and ship to Jamaica

  10. #30
    Join Date
    Dec 2004
    Posts
    476
    Rep Power
    0

    Default

    no thats y i placed the program on here for you to take a look at it
    WHY PAY WHEN YOU CAN GET IT FREE!!!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •