小编Dez*_*ang的帖子

在C中的特定平面中生成随机点

我有一个三维的2D平面:x + y + z = 1,我想在平面上生成随机点(x,y,z).如何选择这些点以使它们均匀分布?

c algorithm

3
推荐指数
1
解决办法
2800
查看次数

scanf函数似乎在c中被跳过

我是C语言的新手,我在下面尝试了此代码,但似乎scanf已被跳过,当我运行此代码时,它仅询问我输入姓名和年龄,并跳过了下面的行,仅在在“ if”语句上方的printf,有人可以帮忙吗?

#include<stdio.h>
void main()
{
    int age;
    char sex;
    char name[20];
    char status;
    printf("Enter your last name\n");
    scanf("%s", &name);

    printf("Enter your age\n");
    scanf("%d", &age);

    printf("Enter sex (M/F)\n");
    scanf("%c", &sex);


    printf("your status,married, single,irrelevant (M/S/I)\n");
    scanf("%c", &status);
    if(age>=16 && sex=='M')
        printf("hello, Mr %s\n", name);
    if(age<16 && sex =='M')
        printf("hello, Master %s\n", name);
    if(sex=='F' && status=='M')
        printf("hello, Mrs %s\n", name);
    if(sex=='F' &&(status=='S' ||status=='I'))
        printf("hello,miss %s\n", name);
}
Run Code Online (Sandbox Code Playgroud)

c

0
推荐指数
1
解决办法
5697
查看次数

标签 统计

c ×2

algorithm ×1