
02.02.2008, 15:34
|
|
Постоянный
Регистрация: 15.08.2006
Сообщений: 404
Провел на форуме: 3811682
Репутация:
641
|
|
Небольшая прозьба, просто сам че-то неврублюсь пока никак ..
кроче есть прога, все написано, пашет.. раскрашена цветами.
По заданию прога выводит 2 матрицы: первая исходная, а вторая с заменой местами двух столбцов. Так вот эти столбцы в первой и второй матрице надо выделить разными цветами, чтобы было видно.
вот прога:
Код:
#include "stdafx.h"
#include <iostream> // for cin/cout
#include <string> // for string
#include <time.h>
#include <windows.h>
using namespace std;
HANDLE hStdout;
int main()
{
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hStdout, BACKGROUND_INTENSITY);
int n;
SetConsoleTextAttribute(hStdout, 7);
cout << "Enter N: ";
cin >> n;
while(n<=0)
{
cout << "\nerror N\nEnter N: ";
cin >> n;
}
SetConsoleTextAttribute(hStdout, 3);
cout << "generate...\n";
int a[10000];
srand(time(0));
for (int i=0; i<n*n; ++i)
{
a[i]=rand()%10;
}
int k=0, l;
SetConsoleTextAttribute(hStdout, 4);
cout << "Enter K: ";
cin >> k;
while(k>n&&k<0)
{
cout << "\nerror K\nEnter K: ";
cin >> k;
}
SetConsoleTextAttribute(hStdout, 8);
cout << "Enter L: ";
cin >> l;
while(l>n&&l<0)
{
cout << "\nerror L\nEnter L: ";
cin >> l;
}
for (int i=0; i<n; ++i)
{
for (int j=0; j<+n; ++j)
cout << a[i*n+j] << ' ';
cout << '\n';
}
// swap k and l columns
for (int i=0; i<n; ++i)
swap (a[i*n+k-1], a[i*n+l-1]); // swap Matr[i][k] and Matr[i][l]
// output result
SetConsoleTextAttribute(hStdout, 6);
cout << "Result:\n";
SetConsoleTextAttribute(hStdout, 6);
for (int i=0; i<n; ++i)
{
for (int j=0; j<+n; ++j)
cout << a[i*n+j] << ' ';
cout << '\n';
}
int x;
int i;
if (i==k){SetConsoleTextAttribute(hStdout, 18);}
getchar();
getchar();
return 0;
}
Заранее спасибо!
|
|
|