关于#c语言#的问题:如何编写c语言程序,模拟3d空间花粉布朗运动

如何编写c语言程序,模拟3d空间花粉布朗运动,输出x,y,z坐标即可

img

如下:

#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

//获取某方向上的随机移动
int getPos(int posOld)
{
    int direct = 1; //方向 1或者-1
    int juli;//移动距离

    int pos;
    direct = rand() % 2; //生成01随机数
    if (direct == 0) direct = -1;  //如果是0,变成-1

    juli = rand() % 10; //生成一个0-10的移动距离

    pos = posOld + direct * juli; //某方向上的移动位置=原来的位置+随机移动方向*随机移动距离
    return pos;
}

int main()
{
    int i, tms = 100;//100次运动
    int x, y, z;
    srand((unsigned int)time(0)); //随机数种子
    printf("请输入初始坐标x y z:");
    scanf("%d %d %d", &x, &y, &z);
    printf("%d,%d,%d\n", x, y, z);
    for (i = 0; i < tms; i++)
    {
        x = getPos(x);
        y = getPos(y);
        z = getPos(z);
        printf("%d,%d,%d\n", x, y, z);
    }
    return 0;
}
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632