标题:为什么输入的数中有1,最后得不到想要的结果
只看楼主
多情剑客
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2015-7-14
 问题点数:0 回复次数:0 
为什么输入的数中有1,最后得不到想要的结果
#include<stdio.h>
#include<stdlib.h>
int i=1;
typedef struct Node
{
        int data;
        struct Node *next;
}node;
node *create()             //创建循环链表
{
        node *head=NULL,*p;
        head=(node *)malloc(sizeof(node));
        p=head;
        printf("请输入每个人手里的数字,如果小于1,那么结束输入,那个人不作数。\n");
        printf("请输入第%d个人手里的数字:",i);
        scanf("%d",&p->data);
        node *s,*p1;
        while(p->data > 0)
        {
                s=(node *)malloc(sizeof(node));
                printf("请输入第%d个人手里的数字:",(++i));
                scanf("%d",&s->data);
                p->next=s;
                p1=p;
                p=s;
        }
        p1->next=head;
        return (head);
}
int main()
{
        int j;
        int m;
        node *temp;
        node *p=create();
        printf("开始人选一个正整数作为第一次报数上限:");
        scanf("%d",&m);
        while(p != p->next)
        {
                if(m == 1)
                {
                        printf("%d->",p->data);
                        temp=p;
                        m=temp->data;
                        p=p->next;
                        free(temp);
                        
                }
                else
                {
                        for(j=1;j<m-1;j++)
                                p=p->next;
                        printf("%d->",p->next->data);
                        temp=p->next;
                        p->next=temp->next;
                        m=temp->data;
                        free(temp);
                        p=p->next;
                }
        }
        printf("%d\n",p->data);
        return 0;
}
搜索更多相关主题的帖子: create include 
2015-07-14 15:46



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




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

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