| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 328 人关注过本帖
标题:帮我看看哪里有问题啊 约瑟夫问题 为什么输出结果的时候总是会显示一个指令 ...
只看楼主 加入收藏
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
快速回复:帮我看看哪里有问题啊 约瑟夫问题 为什么输出结果的时候总是会显示一 ...
数据加载中...
 
   



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

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