Skip to content

Instantly share code, notes, and snippets.

@kostyakoz
Created March 5, 2015 10:21
Show Gist options
  • Save kostyakoz/770eade76d8b0903e9d6 to your computer and use it in GitHub Desktop.
Save kostyakoz/770eade76d8b0903e9d6 to your computer and use it in GitHub Desktop.
Matrix Linear
// Matrix Line.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <ctime>
#include <Windows.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
srand(time(0));
setlocale(LC_ALL, "");
int n, m;
float x;
boolean OK;
cout << "Input n (string number) & m (column number): ";
cin >> n; cin >> m;
float ** ARR = new float *[n];
for (int i = 0; i < n; i++) ARR[i] = new float[m];
cout << "\n";
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
cin >> ARR[i][j];
}
cout << "\n********** MATRIX **********\n\n";
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cout << ARR[i][j] << " ";
}
cout << "\n";
}
cout << "\n****** LINEAR STRINGS ******\n\n";
for (int i = 0; i < n - 1; i++) {
cout << "NUM " << i << ": ";
for (int j = i + 1; j < n; j++) {
OK = true;
for (int k = 0; k < m; k++) {
if ((ARR[i][k] != 0) && (ARR[j][k] != 0)) {
x = ARR[i][k] / ARR[j][k];
break;
} else if (((k - 1) == m) && (ARR[i][k] == 0) && (ARR[j][k] == 0)) OK = false;
}
if (OK) {
for (int k = 1; k < m; k++) {
if ((ARR[i][k] / ARR[j][k]) != x) {
OK = false;
break;
}
}
if (OK) cout << j << "; "; else cout << "-";
}
}
cout << "\n";
}
cout << "\n";
for (int i = 0; i < n; i++) delete[] ARR[i];
delete[] ARR;
system("pause");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment