repl.it
@cream_puff_four/

Magic Square

C++

No description

fork
loading
Files
  • main.cpp
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
using namespace std;
int main() {
	cout<<"Enter a number to start from"<< endl;
	int start;
	cin>>start;
	int base [3][3] = {{8, 1, 6}, {3, 5, 7}, {4, 9, 2}};
	int square [3][3];
	for (int i = 0; i < 3; i ++) {
		for (int j = 0; j < 3; j ++) {
			square [i][j] = base [i][j] + start - 1;
		}
	}
	for (int i = 0; i < 3; i ++) {
		for (int j = 0; j < 3; j ++) {
			cout<<square [i][j]<<" ";
		}
		cout << endl;
	}
	cout<<"Every row, collum, and diagonal adds up to "<<square [0][0] + square [0][1] + square [0][2];
}