Code:
#include <iomanip>
#include<fstream>
#include <cstdlib>
#include <ctime>
#include<iostream>
using namespace std;
int main()
{
ofstream myfile ("sparse 100.txt");
const int i=10,j=10; //number of rows and columns
int AF[i][j],nnz=0;
int cte;
srand( time( 0 ) );
for ( int a = 0; a < i; a++ )
{
for ( int b = 0; b <j; b++ )
{
cte=rand() %220;
if(cte>100)
cte=0;
AF[a][b]=cte;
if(cte!=0)
nnz++;
}
}
if (myfile.is_open())
{
for ( int a = 0; a <i; a++ )
{
for ( int b = 0; b <j; b++ )
{
myfile << AF[a][b]<<endl;
}
}
myfile.close();
}
[U][I][B]const int NNZ=nnz[/B][/I][/U];
int [B][I][U]A[NNZ],J[NNZ][/U][/I][/B],I[i+1],counter=0;
I[0]=1;
for (int a = 0; a <i; a++ )
{
for ( int b = 0; b <j; b++ )
{
if(AF[a][b]!=0)
{
A[counter]=AF[a][b];
J[counter]=b;
counter++;
}
}
I[a]=counter+1;
cout<<"done";
}
return 0;
}
hello,
i'm writing a code to generate a sparse matrix.
i'm having this problem:
error C2466: cannot allocate an array of constant size 0
i know that the declaration of the size of an array should be an int OR of type const int. in the above program, when i assign the value of NNZ as fallows: NNZ=nnz it's considering it as 0. any help plz? any solution for my problem?
thank you in advance :)
Comment