标题:帮我看看哪里有问题啊 约瑟夫问题 为什么输出结果的时候总是会显示一个指令 ...
只看楼主
es小涛
Rank: 2
等 级:论坛游民
帖 子:10
专家分:13
注 册:2014-12-17
结帖率:66.67%
已结贴  问题点数:14 回复次数:1 
帮我看看哪里有问题啊 约瑟夫问题 为什么输出结果的时候总是会显示一个指令错误
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 2
#define len_name 15
void yuesefu(struct data stu[],int m);
struct data
{
    char name[len_name];
    char gender[2];
    int age;
    char num[len_name];
    int password;
}stu[N],out[N];
int main()
{
    int i,m;
    for (i = 0; i < N; i++)
    {
        printf(" please input %d/%d personal information:\n", i + 1,N);
        printf("please input the name:");
        scanf("%s", stu[i].name);
        printf("input the gender:(F or M)");
        scanf("%s", stu[i].gender);
        printf("input the age:");
        scanf("%d", &stu[i].age);
        printf("Enrter the number:");
        scanf("%s", stu[i].num);
        printf("input the password:");
        scanf("%d", &stu[i].password);
        printf("\n");
    }
    printf("Please enter the number to start out");
    scanf("%d", &m);
    yuesefu(stu,m);
    return 0;
}
void yuesefu(struct data stu[], int m)
{
    int i, mark = 0, count = 0;
    int r[N];
    for (i = 0; i < N; i++)
        r[i] = stu[i].password;
    while (1)
    {
        for (i = 0; i < N; i++)
        {
            if (r[i]>0)
            {
                mark++;
                if (mark == m)
                {
                    strcpy(out[count].name,stu[i].name);
                    strcpy(out[count].gender,stu[i].gender);
                    out[count].age=stu[i].age;
                    strcpy(out[count].num,stu[i].num);
                    out[count].password=stu[i].password;
                    m = r[i];
                    r[i] = 0;
                    mark = 0;
                    count++;
                }
            }
        }
        if (count == N)
            break;
    }
    printf("Out of the people:\n");
    for (i = 0; i < N; i++)
        printf("Name :%s\ngender:%s\nage:%d\nnum%s\npassword :%s\n", out[i].name, out[i].gender, out[i].age, out[i].num, out[i].password);
}
搜索更多相关主题的帖子: password personal include 约瑟夫 please 
2015-04-22 19:37
纳兰伽香
Rank: 10Rank: 10Rank: 10
来 自:北京
等 级:贵宾
威 望:10
帖 子:426
专家分:1650
注 册:2015-4-5
得分:14 

风回小院庭芜绿,柳眼春相续
2015-04-22 21:34



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-444380-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.209499 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved