potrebujem vytvorit maticu s nahodnym poctom stlpcov a riadkov, lenze
Kód: Vybrať všetko
int* matica = new int[a][b];Kód: Vybrať všetko
b=rand()%20+2;
a=(b-1)+rand()%10;ako mam udanie velkosti dvojrozmerneho pola nechat na neskor v programe?
Kód: Vybrať všetko
int* matica = new int[a][b];Kód: Vybrať všetko
b=rand()%20+2;
a=(b-1)+rand()%10;
Kód: Vybrať všetko
int** pole;
pole = new int*[num_of_rows];
for(int i = 0; i <= num_of_rows; i++)
pole[i] = new int[num_of_column];Kód: Vybrať všetko
#include "stdafx.h"
#include "iostream"
#include "ctime"
#include "cstdlib"
using namespace std;
int main ()
{
int a,b,x,y,sucet;
int* matica = new int[a];
srand ((unsigned)time(NULL));
a=rand()%26+2;
b=(a-1)+rand()%10;
sucet=2*a+2*(b-2);
cout << "Matica ma po obvode " << sucet << " prvkov\n";
for (x=0; x<b; x++)
{
for (y=0; y<a; y++)
{
matica[a]=rand()%100;
cout.width(a);
cout << matica[a];
}
cout << endl;
}
delete[]matica;
return 0;
}
Kód: Vybrať všetko
1>------ Build started: Project: matica, Configuration: Debug Win32 ------
1>Build started 13. 11. 2011 20:52:32.
1>InitializeBuildStatus:
1> Touching "Debug\matica.unsuccessfulbuild".
1>ClCompile:
1> All outputs are up-to-date.
1> matica.cpp
1>c:\documents and settings\spravca\dokumenty\visual studio 2010\projects\matica\matica\matica.cpp(12): warning C4700: uninitialized local variable 'a' used
1>ManifestResourceCompile:
1> All outputs are up-to-date.
1>Manifest:
1> All outputs are up-to-date.
1>LinkEmbedManifest:
1> All outputs are up-to-date.
1> matica.vcxproj -> C:\Documents and Settings\Spravca\dokumenty\visual studio 2010\Projects\matica\Debug\matica.exe
1>FinalizeBuildStatus:
1> Deleting file "Debug\matica.unsuccessfulbuild".
1> Touching "Debug\matica.lastbuildstate".
1>
1>Build succeeded.
1>
1>Time Elapsed 00:00:00.64
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========Kód: Vybrať všetko
int a,b,x,y,sucet;
int* matica = new int[a];
Kód: Vybrať všetko
#include "stdafx.h"
#include "iostream"
#include "ctime"
#include "cstdlib"
using namespace std;
int main ()
{
int a,b,x,y,sucet;
srand ((unsigned)time(NULL));
a=rand()%9+2;
b=(a-1)+rand()%10;
sucet=(2*a)+(2*(b-2));
int* matica = new int[a];
cout << "Matica ma po obvode " << sucet << " prvkov\n";
for (x=0; x<b; x++)
{
for (y=0; y<a; y++)
{
matica[a]=rand()%100;
cout.width(a);
cout << matica[a];
}
cout << endl;
}
delete []matica;
return 0;
}Kód: Vybrať všetko
1>------ Build started: Project: matica, Configuration: Debug Win32 ------
1>Build started 13. 11. 2011 21:17:56.
1>InitializeBuildStatus:
1> Creating "Debug\matica.unsuccessfulbuild" because "AlwaysCreate" was specified.
1>ClCompile:
1> All outputs are up-to-date.
1> matica.cpp
1>ManifestResourceCompile:
1> All outputs are up-to-date.
1>Manifest:
1> All outputs are up-to-date.
1>LinkEmbedManifest:
1> All outputs are up-to-date.
1> matica.vcxproj -> C:\Documents and Settings\Spravca\dokumenty\visual studio 2010\Projects\matica\Debug\matica.exe
1>FinalizeBuildStatus:
1> Deleting file "Debug\matica.unsuccessfulbuild".
1> Touching "Debug\matica.lastbuildstate".
1>
1>Build succeeded.
1>
1>Time Elapsed 00:00:00.79
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
Kód: Vybrať všetko
'matica.exe': Loaded 'C:\Documents and Settings\Spravca\Dokumenty\Visual Studio 2010\Projects\matica\Debug\matica.exe', Symbols loaded.
'matica.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll', Cannot find or open the PDB file
'matica.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll', Cannot find or open the PDB file
'matica.exe': Loaded 'C:\WINDOWS\system32\msvcp100d.dll', Symbols loaded.
'matica.exe': Loaded 'C:\WINDOWS\system32\msvcr100d.dll', Symbols loaded.
'matica.exe': Loaded 'C:\WINDOWS\system32\user32.dll', Cannot find or open the PDB file
'matica.exe': Loaded 'C:\WINDOWS\system32\gdi32.dll', Cannot find or open the PDB file
'matica.exe': Loaded 'C:\WINDOWS\system32\imm32.dll', Cannot find or open the PDB file
'matica.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll', Cannot find or open the PDB file
'matica.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll', Cannot find or open the PDB file
'matica.exe': Loaded 'C:\WINDOWS\system32\secur32.dll', Cannot find or open the PDB file
'matica.exe': Loaded 'C:\WINDOWS\system32\lpk.dll', Cannot find or open the PDB file
'matica.exe': Loaded 'C:\WINDOWS\system32\usp10.dll', Cannot find or open the PDB file
'matica.exe': Loaded 'C:\WINDOWS\system32\uxtheme.dll', Cannot find or open the PDB file
'matica.exe': Loaded 'C:\WINDOWS\system32\msvcrt.dll', Cannot find or open the PDB file
'matica.exe': Loaded 'C:\Documents and Settings\All Users\Data aplikací\Real\RealPlayer\BrowserRecordPlugin\Chrome\Hook\rpchromebrowserrecordhelper.dll', Cannot find or open the PDB file
'matica.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.4974_x-ww_d889290f\msvcr90.dll', Cannot find or open the PDB file
'matica.exe': Loaded 'C:\WINDOWS\system32\shell32.dll', Cannot find or open the PDB file
'matica.exe': Loaded 'C:\WINDOWS\system32\shlwapi.dll', Cannot find or open the PDB file
'matica.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.4974_x-ww_d889290f\msvcp90.dll', Cannot find or open the PDB file
'matica.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83\comctl32.dll', Cannot find or open the PDB file
'matica.exe': Loaded 'C:\WINDOWS\system32\comctl32.dll', Cannot find or open the PDB file
'matica.exe': Loaded 'C:\WINDOWS\system32\msctf.dll', Cannot find or open the PDB file
'matica.exe': Loaded 'C:\WINDOWS\system32\version.dll', Cannot find or open the PDB file
'matica.exe': Unloaded 'C:\WINDOWS\system32\version.dll'
'matica.exe': Loaded 'C:\WINDOWS\system32\msctfime.ime', Cannot find or open the PDB file
'matica.exe': Loaded 'C:\WINDOWS\system32\ole32.dll', Cannot find or open the PDB file
'matica.exe': Loaded 'C:\WINDOWS\system32\clbcatq.dll', Cannot find or open the PDB file
'matica.exe': Loaded 'C:\WINDOWS\system32\comres.dll', Cannot find or open the PDB file
'matica.exe': Loaded 'C:\WINDOWS\system32\oleaut32.dll', Cannot find or open the PDB file
'matica.exe': Loaded 'C:\WINDOWS\system32\version.dll', Cannot find or open the PDB file
The program '[3756] matica.exe: Native' has exited with code 3 (0x3).
Kód: Vybrať všetko
matica[y]=rand()%100;
cout.width(a);
cout << matica[y];Kód: Vybrať všetko
for (y=0; y<a; y++)
{
matica[a]=rand()%100;
cout.width(a);
cout << matica[a];
}
cout << endl;
Kód: Vybrať všetko
int main ()
{
int a, b, sucet;
srand ((unsigned)time(NULL));
a = rand() % 9 + 2;
b = (a - 1) + rand() % 10;
sucet = (2 * a) + (2 * (b - 2));
int velkostMatice = a*b;//sucet po obvode ? divne cislo
int** matica = new int* [a];
cout << "Matica ma po obvode " << sucet << " prvkov\n";
for (int x = 0; x < a; x++)//pozor b vymenil za a
{
matica[x] = new int[b];
for (int y = 0; y < b; y++)
{
matica[x][y] = rand() % 100;
//cout.width(a);
cout << " " << matica[x][y] << " ";
}
cout << endl;
}
system("pause");
delete[] matica;
return 0;
}
Kód: Vybrať všetko
int** matica = new int* [b];Kód: Vybrať všetko
int** matica; //vytvorenie premennej matica typu pointer na pointer, v ktorom budu cele cisla
matica = new int* [b] //co robim v tomto riadku? prosim v celej vete, nie heslovitoKód: Vybrať všetko
matica[x] = new int[a];