叫autocad 自動 畫很多球
(高顯忠, sjgau4311@gmail.com, 2012-02-05 11:42)
1樓
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
const double pi= (4*atan(1));
typedef struct {
int color;
int xc,yc,zc;
int r;
} ball;
int main(int argc, char *argv[])
{
FILE *f1, *f2;
ball bb[10];
int i;
srand(0x1045);
f1= fopen("yyy.scr", "wt");
double sum= 0;
for (i=0;i<10;i++) {
bb[i].color= rand()%7 + 1;
bb[i].xc= rand()%100;
bb[i].yc= rand()%100;
bb[i].zc= rand()%100;
bb[i].r= rand()%10 + 1;
sum+= (4.0/3)*pi*
(pow((bb[i].r), 3));
fprintf(f1, "color\n%d\n",
bb[i].color);
fprintf(f1, "sphere\n");
fprintf(f1, "%d,%d,%d\n",
bb[i].xc, bb[i].yc, bb[i].zc);
fprintf(f1, "%d\n",
bb[i].r);
}
// fprintf(f1, "\n");
fclose(f1);
printf("sum= %.4lf \n", sum);
system("PAUSE");
return EXIT_SUCCESS;
}