用1-6这6个自然数组成一个三角形,并让这个三角形三条边上数字之和相等

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int a,b,c,d,e,f;
    for(a=1;a<=6;a++)
    {
        for(b=1;b<=6;b++)
        {
            for(c=1;c<=6;c++)
            {
                for(d=1;d<=6;d++)
                {
                    for(e=1;e<=6;e++)
                    {
                        for(f=1;f<=6;f++)
                        {
                            if( a!=b && a!=c && a!=d && a!=e && a!=f
                                     && b!=c && b!=d && b!=e && b!=f
                                             && c!=d && c!=e && c!=f
                                                     && d!=e && d!=f
                                                             && e!=f)
                            {
                                if(a+b+c==a+d+e && c+e+f==a+b+c)
                                {


                                    printf("%d+%d+%d  ",a,b,c);
                                    printf("%d+%d+%d  ",a,d,e);
                                    printf("%d+%d+%d  \n",c,e,f);


                                }
                            }
                        }
                    }
                }
            }
        }
    }


    system("pause");
    return 0;
}


不知道这算不算标准答案,我本意是想在带入一个I变量,让打印结果A+B+C=I,可惜尝试未果,只能如此了

猜你喜欢

转载自blog.csdn.net/weixin_42252769/article/details/80572861