标题:编出程序后,就是组数不能控制,成了死循环,求大佬们帮助
只看楼主
甲级黎庶
Rank: 2
等 级:论坛游民
帖 子:52
专家分:15
注 册:2017-10-4
结帖率:75%
已结贴  问题点数:20 回复次数:6 
编出程序后,就是组数不能控制,成了死循环,求大佬们帮助
我想要输入T组,可是结果是个死循环,不知道哪里的原因
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int T,i;
    scanf("%d",&T);
    int a[4];

    while(T--)
    {
        for(i=1;i<5;i++)
        {
            scanf("%d",&a[i]);
        }
        if(a[1]>=1 && a[1]<=100 && a[2]>=1 && a[2]<=100 && a[3]>=1 && a[3]<=100 && a[4]>=1 && a[4]<=100)
        {
            if((a[1]+a[2])>a[3] && (a[1]-a[2])<a[3])
            {
                printf("T\n");
            }
            else
            {
                if((a[1]+a[2])==a[3] || (a[1]-a[2])==a[3])
                {
                    printf("S\n");
                }
                else
                {
                    if((a[3]+a[2])>a[4] && (a[3]-a[2])<a[4])
                    {
                        printf("T\n");
                    }
                    else
                    {
                        if((a[3]+a[2])==a[4] || (a[3]-a[2])==a[4])
                        {
                            printf("S\n");
                        }
                        else
                        {
                            if((a[1]+a[2])>a[4] && (a[1]-a[2])<a[4])
                            {
                                printf("T\n");
                            }
                            else
                            {
                                if((a[1]+a[2])==a[4] || (a[1]-a[2])==a[4])
                                {
                                    printf("S\n");
                                }
                                else
                                {
                                    if((a[1]+a[4])>a[3] && (a[1]-a[4])<a[3])
                                    {
                                        printf("T\n");
                                    }
                                    else
                                    {
                                        if((a[1]+a[4])==a[3] || (a[1]-a[4])==a[3])
                                        {
                                            printf("S\n");
                                        }
                                        else
                                        {
                                            printf("I\n");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

    }
    return 0;
}
求大佬解惑
搜索更多相关主题的帖子: 控制 死循环 int printf || 
2017-10-29 11:31
炎天
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:桃花岛
等 级:贵宾
威 望:29
帖 子:1218
专家分:4986
注 册:2016-9-15
得分:5 
死循环?  for(i=1;i<5;i++)  //越界

早知做人那么辛苦!  当初不应该下凡
2017-10-29 11:44
甲级黎庶
Rank: 2
等 级:论坛游民
帖 子:52
专家分:15
注 册:2017-10-4
得分:0 

我也不知道
2017-10-29 11:47
甲级黎庶
Rank: 2
等 级:论坛游民
帖 子:52
专家分:15
注 册:2017-10-4
得分:0 
回复 2楼 炎天
我将a[1]到a[5]不用循环输入都是一样的问题
2017-10-29 12:09
zbjzbj
Rank: 12Rank: 12Rank: 12
来 自:郑州
等 级:贵宾
威 望:52
帖 子:620
专家分:3020
注 册:2011-4-22
得分:5 
这代码太难读了,这么多层if
2017-10-29 13:32
pydlq
Rank: 6Rank: 6
等 级:侠之大者
威 望:1
帖 子:129
专家分:488
注 册:2017-9-5
得分:10 
定义数组为a[4],那它的数组元素就只能到a[3]
2017-10-29 14:53
甲级黎庶
Rank: 2
等 级:论坛游民
帖 子:52
专家分:15
注 册:2017-10-4
得分:0 
回复 6楼 pydlq
哦,好的,谢谢大佬
2017-10-30 06:00



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




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

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