[ create a new paste ] login | about

Link: http://codepad.org/9TL35R1Z    [ raw code | output | fork ]

C, pasted on May 10:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

static const int N=32;
typedef struct
{
	float r[N][3];   //position
	float v[N][3];   //velocity
}Particle;

float sq(float a)
{
	return a*a;
}

void init_r(Particle *p) 
{

	int i,j;
	float r2;
	for(i=0;i<N;){
		p->r[i][0]=2*drand48()-1.0;
		p->r[i][1]=2*drand48()-1.0;
		p->r[i][2]=2*drand48()-1.0;
		r2=sqrt(sq(p->r[i][0]) + sq(p->r[i][1]) + sq(p->r[i][2]));
	
		p->v[i][0]=0.0;
		p->v[i][1]=0.0;
		p->v[i][2]=0.0;
		if (r2 <= 1.0) i++;
	}
}

int main(int argc,char** argv)
{
	int i;
	Particle p;
	init_r(&p);
	for(i=0;i<N;i++)
	{
		printf("%f,%f,%f \n",p.r[i][0],p.r[i][1],p.r[i][2]);
	}
	return 0;
}


Output:
1
2
Line 8: error: variably modified 'r' at file scope
Line 9: error: variably modified 'v' at file scope


Create a new paste based on this one


Comments: