开发平台(Platform): (Ex: VC++, GCC, Linux, ...)
Dev-C++
额外使用到的函数库(Library Used): (Ex: OpenGL, ...)
No
问题(Question):
设定一半径为500的圆,随机产生一点于圆内并算出与圆点的距离
现在有个问题就是,我的x1产生出来的值,没有办法像y1这么的随机
喂入的资料(Input):
No
预期的正确结果(Expected Output):
x1:-500~500的值,y1:-500~500的值
错误结果(Wrong Output):
x1感觉有固定的顺序,Ex:-433,-427,-420
程式码(Code):(请善用置底文网页, 记得排版)
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<time.h>
main()
{
int x1,y1;
float r1;
srand(time(NULL));
x1=(rand()%1000)-500;
y1=(rand()%1000)-500;
r1=sqrt(x1*x1+y1*y1);
if(r1<=500)
{
printf("x1 = %d\n",x1);
printf("y1 = %d\n",y1);
printf("r1 = %lf\n",r1);
}
else
{
printf("x1 = %d\n",x1);
printf("y1 = %d\n",y1);
printf("r1 is error\nr1 is %lf\n",r1);
}
}
补充说明(Supplement):
No