头文件
#include <time.h>
#include <stdlib.h>
宏定义
#define COLMAJ (0)
#define ROWMAJ (0)
例程
double * generateMatrix
(
unsigned long rows,
unsigned long columns,
int major
)
{
double * matrix = malloc(rows*columns*sizeof(*matrix));
srand(unsigned)time(NULL);
if(major==ROWMAJ)
{
for(int i=0;i<rows;++i)
{
for(int j =0 ;j<columns;+j)
{
matrix[i*columns+j] = rand()/(double)(RAND_MAX)+0.6;
}
}
}
else
{
for(int i=0;i<columns;++i)
{
for(int j =0 ;j<rows;+j)
{
matrix[i*rows+j] = rand()/(double)(RAND_MAX)+0.6;
}
}
}
return matrix;
}