print a 3x3 magic square where each row and column add up to 15, but instead of numbers it must output roman numerals.
c++
#include <bits/stdc++.h>
using namespace std;
string roman(int x)
{
if(x==1)
return "I";
else if(x==2)
return "II";
else if(x==3)
return "III";
else if(x==4)
return "IV";
else if(x==5)
return "V";
else if(x==6)
return "VI";
else if(x==7)
return "VII";
else if(x==8)
return "VIII";
else if(x==9)
return "IX";
}
// A function to generate odd sized magic squares
void generateSquare(int n)
{
int magicSquare[n][n];
memset(magicSquare, 0, sizeof(magicSquare));
int i = n/2;
int j = n-1;
for (int num = 1; num <= n*n; )
{
if (i == -1 && j == n)
{
j = n-2;
i = 0;
}
else
{
if (j == n)
j = 0;
if (i < 0)
i = n - 1;
}
if (magicSquare[i][j])
{
j -= 2;
i++;
continue;
}
else
magicSquare[i][j] = num++;
j++; i--;
}
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
cout<<roman(magicSquare[i][j])<<" ";
cout<<endl;
}
}
int main()
{
int n = 3;
generateSquare (n);
return 0;
}
print a 3x3 magic square where each row and column add up to 15, but instead...
A magic square is a square of numbers with each row, column, and diagonal of the square adding up to the same sum, called the magic sum. Arrange the numbers,-1,0,1,2,3,4,5,6,and 7 into a magic square. How does the average of these numbers compare with the magic sum?
9. Lo Shu Magic Square The Lo Shu Magic Square is a grid with three rows and three columns that has the following properties: The grid contains the numbers 1 through 9 exactly. The sum of each row, each column, and each diagonal all add up to the same number. This is shown in the following figure · 15 4 9 2-15 3 5 7-15 81 615 15 15 15 15 Write a program that simulates a magic square using...
IN C++ Write a program that uses a 3x3 array and randomly places each integer from 1 to 9 into the nine squares. The program calculates the "magic number" by adding all the numbers in the array and then dividing the sum by 3. The 3x3 array is said to be a "magic square" if the sum of each row, each column, and each diagonal is equal to the magic number. Your program must use at least the following functions:...
Write C++ programs that create TEN(10) different N*N magic squares. A square matrix is the arrangement of the numbers 1, 2, ., N2, in which the sum of rows, columns, and diagonals are the same. The users (i.e., TAs) will specify the size of the square matrix: N. The value N must be an odd number between 3 and 15. Example Run For example, you program is expected to run as the following way. NOTE: We only list 5 magic...
C++ Magic Squares. An n x n matrix that is filled with the numbers 1,2,3,…,n2 is a magic square if the sum of the elements in each row, in each column, and in the two diagonals is the same value. The following algorithm will construct magic n x n squares; it only works if n is odd: Place 1 in the middle of the bottom row. After k has been placed in the (i,j) square, place k+1 into the square...
This assignment requires you to write a program to implement an odd-order Magic Square. Prompt the user to enter the “order” of the square and then produce for the user a magic square of that order. Run your code for at least four different inputs – all odd. ODD ORDER MAGIC SQUARES 1. Start by placing 1 in the middle column of the top row. 2. Continue by always placing the next number (say k+1) in the square diagonally up...
please use java language
please used ArrayList
The Lo Shu Magic Square is a grid with 3 rows and 3 columns, shown in Figure 7-31. The • The sum of each row, each column, and each diagonal all add up to the same number 20. Lo Shu Magic Square Lo Shu Magic Square has the following properties: • The grid contains the numbers 1 through 9 exactly. This is shown in Figure 7-32. In a program you can simulate a...
I need this written in C++. Magic Squares. An n x n matrix that is filled with the numbers 1,2,3,…,n2 is a magic square if the sum of the elements in each row, in each column, and in the two diagonals is the same value. The following algorithm will construct magic n x n squares; it only works if n is odd: Place 1 in the middle of the bottom row. After k has been placed in the (i,j) square,...
Magic squares. An n × n matrix that is filled with the numbers 1, 2, 3, ..., n2 is a magic square if the sum ofthe elements in each row, in each column, and in the two diagonals is the same value. For example,16 3 2 135 10 11 89 6 7 124 15 14 1Write a program that reads in n2 values from the keyboard and tests whether they form a magic squarewhen arranged as a square matrix. You...
Java Magic Square:
A n x n matrix that is filled with the numbers 1, 2, 3,.... n^2 is
a magic square if the sum of the elements in each row, in each
column, and in the two diagonals is the same value.
I need to write an application that gets 16 values as user input,
in any order. Store these values in an ArrayList. When the numbers
are put into a square, this would be a 4x4 two-dimensional
array....