answersLogoWhite

0


Best Answer

The value of a static global variable can never be changed whereas the value of a simple global variable can be changed.

how to create a 3x3 matrix written in c++:

#include

#include//this is only for if you want a string matrix

using namespace.std;

int main()

{

string yourstinghere[3][3];

}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

15y ago

Depends on the language and how you're wanting to add them, but generally it will look something like this.

for(int i =0;i < Example.length;i++)

{

for(int j = 0;j < Example.length;j++)

{

newValue = newValue + Example[i][j];

}

}

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

/* Write a C program that uses functions to perform the following:

i) Addition of Two Matrices

ii) Multiplication of Two Matrices

*/

#include<stdio.h>

void main()

{

int ch,i,j,m,n,p,q,k,r1,c1,a[10][10],b[10][10],c[10][10];

clrscr();

printf("************************************");

printf("\n\t\tMENU");

printf("\n**********************************");

printf("\n[1]ADDITION OF TWO MATRICES");

printf("\n[2]MULTIPLICATION OF TWO MATRICES");

printf("\n[0]EXIT");

printf("\n**********************************");

printf("\n\tEnter your choice:\n");

scanf("%d",&ch);

if(ch<=2 & ch>0)

{

printf("Valid Choice\n");

}

switch(ch)

{

case 1:

printf("Input rows and columns of A & B Matrix:");

scanf("%d%d",&r1,&c1);

printf("Enter elements of matrix A:\n");

for(i=0;i<r1;i++)

{

for(j=0;j<c1;j++)

scanf("%d",&a[i][j]);

}

printf("Enter elements of matrix B:\n");

for(i=0;i<r1;i++)

{

for(j=0;j<c1;j++)

scanf("%d",&b[i][j]);

}

printf("\n =====Matrix Addition=====\n");

for(i=0;i<r1;i++)

{

for(j=0;j<c1;j++)

printf("%5d",a[i][j]+b[i][j]);

printf("\n");

}

break;

case 2:

printf("Input rows and columns of A matrix:");

scanf("%d%d",&m,&n);

printf("Input rows and columns of B matrix:");

scanf("%d%d",&p,&q);

if(n==p)

{

printf("matrices can be multiplied\n");

printf("resultant matrix is %d*%d\n",m,q);

printf("Input A matrix\n");

read_matrix(a,m,n);

printf("Input B matrix\n");

/*Function call to read the matrix*/

read_matrix(b,p,q);

/*Function for Multiplication of two matrices*/

printf("\n =====Matrix Multiplication=====\n");

for(i=0;i<m;++i)

for(j=0;j<q;++j)

{

c[i][j]=0;

for(k=0;k<n;++k)

c[i][j]=c[i][j]+a[i][k]*b[k][j];

}

printf("Resultant of two matrices:\n");

write_matrix(c,m,q);

}

/*end if*/

else

{

printf("Matrices cannot be multiplied.");

}

/*end else*/

break;

case 0:

printf("\n Choice Terminated");

exit();

break;

default:

printf("\n Invalid Choice");

}

getch();

}

/*Function read matrix*/

int read_matrix(int a[10][10],int m,int n)

{

int i,j;

for(i=0;i<m;i++)

for(j=0;j<n;j++)

scanf("%d",&a[i][j]);

return 0;

}

/*Function to write the matrix*/

int write_matrix(int a[10][10],int m,int n)

{

int i,j;

for(i=0;i<m;i++)

{

for(j=0;j<n;j++)

printf("%5d",a[i][j]);

printf("\n");

}

return 0;

}

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

#include<stdio.h>

void main()

{

int a[3][3],b[3][3],c[3][3],i,j;

printf("Enter the First 3x3 Matrix : ");

for(i=0;i<3;i++)

{

for(j=0;j<3;j++)

scanf("%d",&a[i][j]);

}

printf("Enter the Second 3x3 Matrix : ");

for(i=0;i<3;i++)

{

for(j=0;j<3;j++)

scanf("%d",&b[i][j]);

}

printf("\nThe Sum of Matrices is : ");

for(i=0;i<3;i++)

{

for(j=0;j<3;j++)

{

c[i][j]=a[i][j]+b[i][j];

printf("%d ",&c[i][j];

}

printf("\n");

}

printf("\n\nThe Difference of Matrices is : ");

for(i=0;i<3;i++)

{

for(j=0;j<3;j++)

{

c[i][j]=a[i][j]-b[i][j];

printf("%d ",&c[i][j];

}

printf("\n");

}

}

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

Presumably, both the original matrices and the result matrix would be stored in 2-dimensional arrays; to do the actual addition, write two "for" loops, one for each row, and one for each column. Inside the inner "for" loop, just add the corresponding elements and place the result in the result matrix.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program to subtract two 3x3 matrices?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

C program for upper triangular matrix for a given matrix?

This sounds very much like a homework problem. If you work on it and get started, you found a great place to ask a specific question. However, this is not a place to have your homework done for you.


How many wrong answers are there for a Rubik's Cube?

One 3x3? Over 4 quadrillion possibilities (4,000,000,000,000,000+) possibilities! ALL the different Rubik's cube versions? Let's not even go there, but I estimate at least 10 to 50 quadrillion (50,000,000,000,000,000+) possibilities!


How do you write a java package program for addition?

A number of well-tested open-source Matrix Java libraries are available. Best to find and use one that's been around for a while since most of the bugs have been worked out. If you need to write your own it's still worth-while to examine the APIs of those libraries first.JAMA is a free Java library for basic linear algebra and matrix operations developed as a straightforward public-domain reference implementation by MathWorks and NIST.Example of Use. The following simple example solves a 3x3 linear system Ax=b and computes the norm of the residual.double[][] array = {{1.,2.,3},{4.,5.,6.},{7.,8.,10.}};Matrix A = new Matrix(array);Matrix b = Matrix.random(3,1);Matrix x = A.solve(b);Matrix Residual = A.times(x).minus(b);double rnorm = Residual.normInf();


Write a program using one print statement to print the asterisks triangle?

#include&lt;stdio.h&gt; #include&lt;conio.h&gt; int main() { int i,j,k,row,m; printf("Enter the no of rows:"); scanf("%d",&amp;row); m=row; for(i=0;i&lt;m;i++) { printf("\n"); for(k=0;k&lt;row;k++) printf(" "); for(j=0;j&lt;=i;j++) printf(" *"); row--; } getch(); }


Write a program for Multiplication of two matrices in java?

//Matrix multiplication import java.util.Scanner; public class Matrix { public static void main(String args[]) { Scanner s= new Scanner(System.in); int i,j,k; System.out.println("enter the value of n"); int n=s.nextInt(); int a[][]=new int[n][n]; int b[][]=new int[n][n]; int c[][]=new int[n][n]; System.out.println("enter the array elements of a:"); for(i=0;i&lt;n;i++) { for(j=0;j&lt;n;j++) { a[i][j]=s.nextInt(); } }//end of a matrix System.out.println("enter the array elements of b:"); for(i=0;i&lt;n;i++) { for(j=0;j&lt;n;j++) { b[i][j]=s.nextInt(); } }//end of b matrix System.out.println("the result matrix is:"); for(i=0;i&lt;n;i++) { for(j=0;j&lt;n;j++) { for(k=0;k&lt;n;k++) { c[i][j]+=a[i][k]*b[k][j]; } } } for(i=0;i&lt;n;i++) { for(j=0;j&lt;n;j++) { System.out.print(+c[i][j]); }System.out.println(); } }//end of main }//end of class

Related questions

Write a program to substract two 3x3 matrices?

Subtract3by3 (double *a, double *b) { int i, j for (i=0; i&lt;3; i++) for (j=0; j&lt;3; j++) a[i*3+j] -= b[i*3+j]; }


Write a program for 3x3 matrix?

#include&lt;stdio.h&gt; #include&lt;conio.h&gt; void main()


Can you write a program that implements cramers rule for 2x2 and 3x3 matrix?

Yes I can. I did it in QBasic about 15 years ago.


Write a 8085 microprocessor program to find A inverse and A transpose if A is a 3x3 matrix?

Sp[[Q/Write a 8085 microprocessor program to find A inverse and A transpose if A is a 3x3 matrix|Answer]]ell chec[[Q/Write a 8085 microprocessor program to find A inverse and A transpose if A is a 3x3 matrix&amp;action=edit&amp;section=new|Answer it!]]k your answe[[Q/Discuss:Write a 8085 microprocessor program to find A inverse and A transpose if A is a 3x3 matrix|Disc]][[help/answering questions|guidelin]]Spell check your answeresussionr[[help/signing in|full benefits]] Save C[[Q/Write a 8085 microprocessor program to find A inverse and A transpose if A is a 3x3 matrix|Write a 8085 microprocessor program to find A inverse and A transpose if A is a 3x3 ]][[Q/Write a 8085 microprocessor program to find A inverse and A transpose if A is a 3x3 matrix&amp;action=edit&amp;section=new|Answering 'Write a 8085 microprocessor program to find A inverse and A transpose if A is a 3x3 matrix?']]matrix?ancel[[Q/How many animals are in West Texas|How many animals are in West Texas?]][[Q/How do you increase the number of four wheelers vehicles for servicing in a Service workshop|How do you increase the number of four wheelers vehicles for servicing in a]][[Q/How do you increase the number of four wheelers vehicles for servicing in a Service workshop|How do you increase the number of four wheelers vehicles for servicing in a Service workshop?]] Service workshop?[[Q/How do you increase the number of four wheelers vehicles for servicing in a Service workshop|How do you increase the number of four wheelers vehicles for servicing in a Service workshop?]]More Q&amp;A


How do you solve a 3x3 magic square with the sum of 6?

A normal 3x3 magic square has a sum of 15. So you subtract 3 from each number in the square.


How many matrices of order 3 can have elements 0 or 1?

A 3x3 matrix has 9 elements. If each element can be either 0 or 1 only (two options) then there are 2^9 = 512 possibilities.


What does S R followed by a number mean?

If you mean what does something like SL(3, R) mean, it is the group of all 3X3 matrices with determinant 1, with real entries, under matrix multiplication.


3x3=9?

y


What is 9 as a product of primes?

3x3


Is 12 3x3?

no 3x3 is 9 3x4 is 12


How many squares on a 3x3?

Multiple them! 3x3=9 squares!


How many different ways can you use the digits 3 and 5 to write expressions in exponential form What are the expressions?

3x3. 5x5