Написал код по рандомному формированию массива. Теперь хочу что бы он стал двумерным. Что, где добавить?
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>
#define max_value 30
void swap(double* p1, double* p2)
{
double tmp = *p1;
*p1 = * p2;
*p2 = tmp;
}
void sort(double* vector, unsigned int size)
{
signed short int swapping = 1;
unsigned int j = 0;
while(swapping > 0)
{
swapping = -1;
for (j = 0; j < size - 1; ++j)
if (vector[j] > vector[j + 1])
{
swap(vector + j, vector + j + 1);
swapping = 1;
}
}
}
int main()
{
unsigned int size, i = 0;
double* vector;
srand((unsigned int)time(NULL));
printf("Enter the size of the vector\n");
scanf("%d", &size);
vector = (double*)malloc(sizeof(double) * size);
if (vector == NULL)
{
perror("Out of memory");
_getch();
return 0;
}
printf("Vector:\n");
for ( ; i < size; ++i)
printf("%4.2lf ", vector[i] = rand() % max_value);
sort(vector, size);
printf("\nSorting array\n");
for (i = 0 ; i < size; ++i)
printf("%4.2lf ", vector[i]);
system("pause");
free(vector);
return 0;
}