Skip to content

Instantly share code, notes, and snippets.

@janisozaur
Created May 26, 2011 16:24
Show Gist options
  • Save janisozaur/993469 to your computer and use it in GitHub Desktop.
Save janisozaur/993469 to your computer and use it in GitHub Desktop.
diagonal
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <fstream>
using namespace std;
int main(int argc, char *argv[])
{
int n;
vector<int> m;
ifstream file;
file.open("i2", ifstream::in);
if (!file.is_open()) {
cerr << "error" << endl;
return 1;
}
while (file) {
file >> n;
m.push_back(n);
}
int a = sqrt(m.size());
for (int i = 0; i < a; i++) {
for (int j = i; j < a; j++) {
cout << setw(3) << m.at(i * a + j);
}
cout << endl;
}
file.close();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment