-
Notifications
You must be signed in to change notification settings - Fork 0
/
zadanie2
53 lines (33 loc) · 1010 Bytes
/
zadanie2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <cstdio>
#include <stdlib.h>
#include <time.h> //bilioteki dzieki ktorym mozemy losowac
int main(int argc, char** argv)
{
int size=0 ;
char buffer[256];
srand( time( NULL ) ); //uruchomienie czasu
printf("Podaj wartosc tablicy = "); //pobieranie rozmiaru tablicy
fgets (buffer, 256, stdin);
size = atoi (buffer);
//tworzenie tablicy
float ** table = new float *[size]; //alokacja pamieci
for(int i=0 ; i < size ; i++)
{
table[i]= new float [size];
for(int j=0 ; j <size ; j++) table[i][j] = 1.0 * rand() / (RAND_MAX - 1);
}
//wyswietlenei zawartosci tablicy do 4 miejsc po przecinku
for(int i=0 ; i < size ; i++)
{
for(int j=0 ; j <size ; j++)
{
printf(" %.4f ", table[i][j]); // wyswietlenie do 4 liczb po przecinku
}
printf("\n");
}
//zwalnienie pamieci
for(int i=0 ; i <size ; i++)
delete [] table [i]; //uwalnianie pamieci
delete [] table ; //uwalnanie pamieci
table = NULL; // wyczyszczeni wskaznika
}