题目要求:
有一种方阵被称为“魔幻方阵”。所谓魔幻方阵是指在n*n的矩阵中填写1~n2这n2个数字,使得它的每一行、每一列以及两个对角线之和均相等。例如三阶魔幻方阵如下:
它的每一行、每一列以及两个对角线之和均为15。编写一个程序,打印出一种三阶的魔幻方阵。
#include
#include
#include
double getPI(int n);
void main()
{
double PI;
int n;
printf("Please enter the number of random points for test
");
scanf("%d",&n);
PI=getPI(n);
printf("The similar value of PI is
%f
",PI);
// getchar();
getche();
}
double getPI(int n)
{
int inCircle=0;
float x,y;
int count=n;
while(count)
{
x=rand();
y=rand();
if(x*x+y*y<=10000)
inCircle++;
count--;
}
return 4.0*inCircle/n;
} | 留言与评论(共有 0 条评论) “” |