# How do you write a c plus plus program to add a magic square matrix?

Let me know if this code works

#include <iostream>

#include <iomanip>

using namespace std;

int size(bool flag)

{

int test; if(flag)

{

do

{

test=(int)(double(rand())/double(RAND_MAX)*14.0+3.0);

}

while(test%2==0);

return test;

}

else return 7;

}

int main()

{

int n = 7;

int row, col, size;

int magic[19][19];

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

{

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

{

magic[j][k] = 0;

}

}

row=1; col=(n+1)/2;

magic[row-1][col-1]=1;

for(int i=2 ; i<=(n*n) ; i++)

{

row-=1;

col-=1;

if(row==0 && col==0)

{

col++; row+=2;

}

else if(row==0) row=n;

else if(col==0) col=n;

else if(magic[row-1][col-1]!=0)

{ col++; row+=2;

}

magic[row-1][col-1]=i;

}

for (row=1; row<=n; row++)

for(col=1; col<=n; col++)

magic[row][n+1]+=magic[row][col];

for(col=1; col<=n; col++)

for(row=1; row<=n; row++)

magic[n+1][col] += magic[row][col];

for(int r=0; r<(n+1) ; r++)

{

cout<<endl;

for(int c=0; c<(n+1) ; c++)

{

cout << setw (5) << magic[r][c];

} cout<<endl;

}

return 0;

}

### How do you write Square program using vb?

write a vb program to find the magic square Read More

### A c program to square matrix?

A C program to square matrix is a math problem. In the math problem you write down all the outer boundary values of matrix in a circle, then write down the inner value. Read More

### How do you Write A program in c language for checking a diagonal matrix?

Write a program in c++ that take input in a integer matrix of size 4*4 and find out if the entered matrix is diagonal or not. Read More

### Write a c program to find eigenvalue of a matrix?

Yes, do write. That's what you always have to do when you have got a homework-program. Read More

### Wap to build a sparse matrix as an arraywrite functions to check if the sparse matrix is a square diagonal or lower triangular or upper triagular or tridiagonal matrix?

write a programe to build a sparse matrix as an array. write function to check if the sparse matrix is a square, diagonal,lower triangular, upper triangular or tridiagonal matrix Read More

### 2x2 matrix multiplication program in 8085 processor?

how to write a program for matrix multiplication in microprocesspr Read More

### Write a program to print the sum of a sparse matrix?

This is a directive, not a question. Read More

### How do you write a java program to find the transpose of the matrix for the given elements?

You basically write a nested for loop (one for within another one), to copy the elements of the matrix to a new matrix. Read More

### How do you write a C-program for matrix addition and multiplication?

A C-program can be written for matrix addition and multiplication simply by using the two dimensional array function. Read More

### How do you write c program to perform sum of elements of matrix using pointers with functions?

i cant write Read More

### Is it more efficient to store the data in a matrix then write it to the file at the end of the program or to write each element to the file as the program runs?

It shouldn't make significant difference, only if the matrix is huge -- in that case you shouldn't store it in memory. Read More

### Write a test program that prints a 3 by 3 matrix?

4.(Displaying matrix of 0s and 1s ) write a method that displays by n by n matrix using the following header : Public static void printMatrix(int n) Each element is o or 1,which is generated randomely. Write a test program that prints a 3 by 3 matrix that may look like this: 010 000 111 4.(Displaying matrix of 0s and 1s ) write a method that displays by n by n matrix using the following… Read More

### Write a program to perform addition of two matrix using the concept of array of pointer in c language?

Write a program to add two matrices using the concept of arrays. Read More

### Write a C program using dynamic memory allocation to find the sum of elements of a matrix?

Did you know that memory allocation is not needed to display the matrix? However, the C program is to find the sum of all the elements. Read More

### How do you write a C program for a matrix multiplication using array?

Write your program and if you are having a problem post it here with a description of the problem you are having. What you are asking is for someone to do your homework for you. Read More

### How can you write a program which proves that a multiple of a matrix and its determinant is an identity matrix?

Automated proofs are a complicated subject. If you are not an expert on the subject, all you can hope for is to write a program where you can input a sample matrix (or that randomly generates one), and verifies the proposition for this particular case. If the proposition is confirmed in several cases, this makes the proposition plausible, but is by no means a formal proof. Better try to prove it without writing any program… Read More

### How to write a c program to print upper triangular and lower triangular matrix elements for a given matrix?

displaying the apper & lower triangle matrixe in c++ Read More

### Write a c program to determine whether a matrix is singular or not?

A c program is also known as a computer program. A singular matrix has no inverse. An equation to determine this would be a/c=f. <<>> The determinant of a singular matix is zero. Read More

### How do you write a magic square program with qbasic?

Answer You're better off using a program like Visual Basic or C++ to do that. QBasic doesn't have very many capabilities. Answer QBasic is quite capable. It is certainly capable of solving a magic squares problem. Read More

### Write a program using iostreams to take as input two multi-dimensional arrays and print their sum as output Matrix Addition in Matrix format?

http://www.assignmentsclub.com/ Read More

### 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. Read More

### Write a program that input a positive integer and prints a triangle using for loop?

write a program that reads in the size of the side of square and then pints a hollow square of that size out of asterisks and blanks? Read More

### Write a c program to accept a numbers and generate square root cube and exponential values?

write a c program to accept a number and generate a square root cube and exponential values Read More

### How do you write a program that calculates the sum of the matrix elements given numbers?

ring me and ill explain - 086 22222222222222227 ring me Read More

### 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&action=edit§ion=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… Read More

### How do you write a program of matrix multiplication in a simple way?

you can write by two ways 1 by giving the size of array at declaration 2 by checking condition Read More

### What are the disadvantages of stack and queue?

write a program in c language that is able to compute the determinant of any 5*5 matrix from your program with at least five examples and print the result Read More

### To Write program in Java to create applets to Create a color palette with matrix of buttons using applet viewer?

getting the code Read More

### Write a C program using dynamic memory allocation to add two matrices?

I want to make dynamic matrix multiplication Read More

### Write a c program using dynamic memory allocation to create a matrix?

/*dynamically creates a matrix with 'm' rows and 'n' columns;the matrix can store integer values*/ int **matrix; int i,j; matrix=malloc(m*sizeof(int *)); for(i=0;i<m;++i) matrix[i]=malloc(n*sizeof(int)); Read More

### How do you write a java program to find the square root of a number?

You can use the Math.sqrt() method. Read More

### Write a program on Trace of matrix in C?

#include<stdio.h> void main() { int a[6][6],n,n1,i,sum=0; printf("Enter the order of the matrix"); scanf("%d %d"'&n,&n1); if(n==n1) { printf("Enter the matrix"); for(i=0;i<n;i++) for(j=0;j<n;j++) scanf("%d",&a[i][j]); printf("The matrix is\n"); for(i=0;i<n;i++) { for(j=0;j<n;j++) printf("%d\t",a[i][j]); printf("\n"); } for(i=0;i<n;i++) sum+=a[i][i]; printf("Trace of the matrix is=%d",sum); } else printf("Enter a square matrix\n"); } Other than the fact that the program given will fail for a square matrix which is more than 6x6 (either with odd results or probably a sigsegv) and will fail… Read More

### How do you write a c program to find square of a no using call by value?

int square (int N) return N*N; Read More

### Write a program to substrate two matrixs in two dimension array?

You need to specify the language in which you want the subtraction of the two matrix in two dimension array written. Read More

### How do you Write a C program for matrix addition?

for (i=0; i<IMAX; i++) for (j=0; j<JMAX; j++) c[i,j] = a[i,j] + b[i,j]; Read More

### Write a program to display Identity matrix?

#include <stdio.h> void main() { int a,b,c,i,j; printf("Enter the number of rows for square matrix : "); scanf("%d",&a); for(i=1;i<=a;i++) { for(c=1,j=1;j<=a;j++,c++) { if(c==i) printf("1 "); else printf("0 "); } printf("\n"); } getch(); } Read More

### Write a program to find whether a given number is a perfect square?

:/ Just square root the number with a calculator. If it isn't "just" a number, then its not a perfect square. Read More

### Write a program to add two 3x3 matrices in java?

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. Read More

### Need to write magic Johnson what adders can i write magic Johnson?

Stretchtowing24hrs@gmail.com Read More

### Write adjacency and incidence matrix for all the graphs developed?

adjacency matrix- since the edges are the relationship between two vertices ,the graph can be represented by a matrix, Read More

### Write a c plus plus program for finding the inverse of a given matrix?

Use the Eigen library to find the inverse of matrices. It is simpler and more efficient than trying to write your own. The only reason to write your own is when you have a better, more efficient method than those that already exist. Read More