| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1309 人关注过本帖
标题:怎么将C++中的开头 # include <iostream> using namespace std; 改成C语言的 ...
取消只看楼主 加入收藏
vitozzz
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2020-12-31
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:2 
怎么将C++中的开头 # include <iostream> using namespace std; 改成C语言的开头?
怎么将C++中的开头
# include <iostream>
using namespace std;
改成C语言的开头?
搜索更多相关主题的帖子: std namespace include using C语言 
2020-12-31 10:42
vitozzz
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2020-12-31
收藏
得分:0 
那怎么将这个C++程序改为C语言程序了?求大神们看看
# include <iostream>
using namespace std;
double sum(int a, int b)//加法
{
    return (a + b);
}
double sub(int a, int b)//减法
{
    return (a - b);
}
double mul(int a, int  b)//乘法
{
    return (a * b);
}
double divi(int a, int b)//除法
{
    return (a / b);
}
int main()//主函数
{
    int a, b, c, d;
    int kinds = 0;//kinds表示算法的总数
    cout << "请输入4个数字\n";
    cin >> a >> b >> c >> d;
    double (*suan24[4])(int, int) = { sum,sub,mul,divi };//主要的算法函数
    char p[4] = { '+','-','*',' /' };
    //第一种顺序
    for (int i1 = 0; i1 < 4; i1++)
    {
        for (int j = 0; j < 4; j++)
        {
            for (int m = 0; m < 4; m++)
            {
                int result = suan24[i1](suan24[j](suan24[m](a, b), c), d);
                if (result == 24)
                {
                    cout << "这四个数能算出24,其中一种解法为:\n";
                    cout << "(" << "(" << a << p[m] << b << ")" << p[j] << c << ")" << p[i1] << d << "=24" << endl;
                    kinds += 1;
                }
            }
        }
    }
    //第二种顺序
    for (int i2 = 0; i2 < 4; i2++)
    {
        for (int j = 0; j < 4; j++)
        {
            for (int m = 0; m < 4; m++)
            {
                int result = suan24[i2](suan24[j](suan24[m](b, c), a), d);
                if (result == 24)
                {
                    cout << "这四个数能算出24,其中一种解法为:\n";
                    cout << "(" << "(" << b << p[m] << c << ")" << p[j] << a << ")" << p[i2] << d << "=24" << endl;
                    kinds += 1;
                }
            }
        }
    }
    //第三种顺序
    for (int i3 = 0; i3 < 4; i3++)
    {
        for (int j = 0; j < 4; j++)
        {
            for (int m = 0; m < 4; m++)
            {
                int result = suan24[i3](suan24[j](suan24[m](c, d), b), a);
                if (result == 24)
                {
                    cout << "这四个数能算出24,其中一种解法为:\n";
                    cout << "(" << "(" << c << p[m] << d << ")" << p[j] << b << ")" << p[i3] << a << "=24" << endl;
                    kinds += 1;
                }
            }
        }
    }
    //第四种顺序
    for (int i4 = 0; i4 < 4; i4++)
    {
        for (int j = 0; j < 4; j++)
        {
            for (int m = 0; m < 4; m++)
            {
                int result = suan24[i4](suan24[j](suan24[m](b, c), d), a);
                if (result == 24)
                {
                    cout << "这四个数能算出24,其中一种解法为:\n";
                    cout << "(" << "(" << b << p[m] << c << ")" << p[j] << d << ")" << p[i4] << a << "=24" << endl;
                    kinds += 1;
                }
            }
        }
    }
    //第五种顺序
    for (int i5 = 0; i5 < 4; i5++)
    {
        for (int j = 0; j < 4; j++)
        {
            for (int m = 0; m < 4; m++)
            {
                int result = suan24[i5](suan24[j](suan24[m](a, c), b), d);
                if (result == 24)
                {
                    cout << "这四个数能算出24,其中一种解法为:\n";
                    cout << "(" << "(" << a << p[m] << c << ")" << p[j] << b << ")" << p[i5] << d << "=24" << endl;
                    kinds += 1;
                }
            }
        }
    }
    //第六种顺序
    for (int i6 = 0; i6 < 4; i6++)
    {
        for (int j = 0; j < 4; j++)
        {
            for (int m = 0; m < 4; m++)
            {
                int result = suan24[i6](suan24[j](suan24[m](a, c), d), b);
                if (result == 24)
                {
                    cout << "这四个数能算出24,其中一种解法为:\n";
                    cout << "(" << "(" << a << p[m] << c << ")" << p[j] << d << ")" << p[i6] << b << "=24" << endl;
                    kinds += 1;
                }
            }
        }
    }
    //第七种顺序
    for (int i7 = 0; i7 < 4; i7++)
    {
        for (int j = 0; j < 4; j++)
        {
            for (int m = 0; m < 4; m++)
            {
                int result = suan24[i7](suan24[j](suan24[m](a, d), b), c);
                if (result == 24)
                {
                    cout << "这四个数能算出24,其中一种解法为:\n";
                    cout << "(" << "(" << a << p[m] << d << ")" << p[j] << b << ")" << p[i7] << c << "=24" << endl;
                    kinds += 1;
                }
            }
        }
    }
    //第八种顺序
    for (int i8 = 0; i8 < 4; i8++)
    {
        for (int j = 0; j < 4; j++)
        {
            for (int m = 0; m < 4; m++)
            {
                int result = suan24[i8](suan24[j](suan24[m](a, d), c), b);
                if (result == 24)
                {
                    cout << "这四个数能算出24,其中一种解法为:\n";
                    cout << "(" << "(" << a << p[m] << d << ")" << p[j] << c << ")" << p[i8] << b << "=24" << endl;
                    kinds += 1;
                }
            }
        }
    }
    //第九种顺序
    for (int i9 = 0; i9 < 4; i9++)
    {
        for (int j = 0; j < 4; j++)
        {
            for (int m = 0; m < 4; m++)
            {
                int result = suan24[i9](suan24[j](suan24[m](b, d), c), a);
                if (result == 24)
                {
                    cout << "这四个数能算出24,其中一种解法为:\n";
                    cout << "(" << "(" << b << p[m] << d << ")" << p[j] << c << ")" << p[i9] << a << "=24" << endl;
                    kinds += 1;
                }
            }
        }
    }
    //第十种顺序
    for (int i10 = 0; i10 < 4; i10++)
    {
        for (int j = 0; j < 4; j++)
        {
            for (int m = 0; m < 4; m++)
            {
                int result = suan24[i10](suan24[j](suan24[m](b, d), a), c);
                if (result == 24)
                {
                    cout << "这四个数能算出24,其中一种解法为:\n";
                    cout << "(" << "(" << b << p[m] << d << ")" << p[j] << a << ")" << p[i10] << c << "=24" << endl;
                    kinds += 1;
                }
            }
        }
    }
    //第十一种顺序
    for (int i11 = 0; i11< 4; i11++)
    {
        for (int j = 0; j < 4; j++)
        {
            for (int m = 0; m < 4; m++)
            {
                int result = suan24[i11](suan24[j](suan24[m](c, d), a), b);
                if (result == 24)
                {
                    cout << "这四个数能算出24,其中一种解法为:\n";
                    cout << "(" << "(" << c << p[m] << d << ")" << p[j] << a << ")" << p[i11] << b << "=24" << endl;
                    kinds += 1;
                }
            }
        }
    }
    //第十二种顺序
    for (int i12 = 0; i12 < 4; i12++)
    {
        for (int j = 0; j < 4; j++)
        {
            for (int m = 0; m < 4; m++)
            {
                int result = suan24[i12](suan24[j](suan24[m](b, a), c), d);
                if (result == 24)
                {
                    cout << "这四个数能算出24,其中一种解法为:\n";
                    cout << "(" << "(" << b << p[m] << a << ")" << p[j] << c << ")" << p[i12] << d << "=24" << endl;
                    kinds += 1;
                }
            }
        }
    }
    if (kinds == 0)
    {
        cout << "这一组数不能算出24点\n";
    }
    else
        cout << "这组数一共有" << kinds << "种算法\n";
    return 0;
}
2020-12-31 18:17
vitozzz
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2020-12-31
收藏
得分:0 
回复 2楼 rjsp
那大佬,怎么将这个C++程序改为C语言程序?(我主要把cout改为printf后,里面的内容不会改)
# include <iostream>
using namespace std;
double sum(int a, int b)//加法
{
    return (a + b);
}
double sub(int a, int b)//减法
{
    return (a - b);
}
double mul(int a, int  b)//乘法
{
    return (a * b);
}
double divi(int a, int b)//除法
{
    return (a / b);
}
int main()//主函数
{
    int a, b, c, d;
    int kinds = 0;//kinds表示算法的总数
    cout << "请输入4个数字\n";
    cin >> a >> b >> c >> d;
    double (*suan24[4])(int, int) = { sum,sub,mul,divi };//主要的算法函数
    char p[4] = { '+','-','*',' /' };
    //第一种顺序
    for (int i1 = 0; i1 < 4; i1++)
    {
        for (int j = 0; j < 4; j++)
        {
            for (int m = 0; m < 4; m++)
            {
                int result = suan24[i1](suan24[j](suan24[m](a, b), c), d);
                if (result == 24)
                {
                    cout << "这四个数能算出24,其中一种解法为:\n";
                    cout << "(" << "(" << a << p[m] << b << ")" << p[j] << c << ")" << p[i1] << d << "=24" << endl;
                    kinds += 1;
                }
            }
        }
    }
    //第二种顺序
    for (int i2 = 0; i2 < 4; i2++)
    {
        for (int j = 0; j < 4; j++)
        {
            for (int m = 0; m < 4; m++)
            {
                int result = suan24[i2](suan24[j](suan24[m](b, c), a), d);
                if (result == 24)
                {
                    cout << "这四个数能算出24,其中一种解法为:\n";
                    cout << "(" << "(" << b << p[m] << c << ")" << p[j] << a << ")" << p[i2] << d << "=24" << endl;
                    kinds += 1;
                }
            }
        }
    }
    //第三种顺序
    for (int i3 = 0; i3 < 4; i3++)
    {
        for (int j = 0; j < 4; j++)
        {
            for (int m = 0; m < 4; m++)
            {
                int result = suan24[i3](suan24[j](suan24[m](c, d), b), a);
                if (result == 24)
                {
                    cout << "这四个数能算出24,其中一种解法为:\n";
                    cout << "(" << "(" << c << p[m] << d << ")" << p[j] << b << ")" << p[i3] << a << "=24" << endl;
                    kinds += 1;
                }
            }
        }
    }
    //第四种顺序
    for (int i4 = 0; i4 < 4; i4++)
    {
        for (int j = 0; j < 4; j++)
        {
            for (int m = 0; m < 4; m++)
            {
                int result = suan24[i4](suan24[j](suan24[m](b, c), d), a);
                if (result == 24)
                {
                    cout << "这四个数能算出24,其中一种解法为:\n";
                    cout << "(" << "(" << b << p[m] << c << ")" << p[j] << d << ")" << p[i4] << a << "=24" << endl;
                    kinds += 1;
                }
            }
        }
    }
    //第五种顺序
    for (int i5 = 0; i5 < 4; i5++)
    {
        for (int j = 0; j < 4; j++)
        {
            for (int m = 0; m < 4; m++)
            {
                int result = suan24[i5](suan24[j](suan24[m](a, c), b), d);
                if (result == 24)
                {
                    cout << "这四个数能算出24,其中一种解法为:\n";
                    cout << "(" << "(" << a << p[m] << c << ")" << p[j] << b << ")" << p[i5] << d << "=24" << endl;
                    kinds += 1;
                }
            }
        }
    }
    //第六种顺序
    for (int i6 = 0; i6 < 4; i6++)
    {
        for (int j = 0; j < 4; j++)
        {
            for (int m = 0; m < 4; m++)
            {
                int result = suan24[i6](suan24[j](suan24[m](a, c), d), b);
                if (result == 24)
                {
                    cout << "这四个数能算出24,其中一种解法为:\n";
                    cout << "(" << "(" << a << p[m] << c << ")" << p[j] << d << ")" << p[i6] << b << "=24" << endl;
                    kinds += 1;
                }
            }
        }
    }
    //第七种顺序
    for (int i7 = 0; i7 < 4; i7++)
    {
        for (int j = 0; j < 4; j++)
        {
            for (int m = 0; m < 4; m++)
            {
                int result = suan24[i7](suan24[j](suan24[m](a, d), b), c);
                if (result == 24)
                {
                    cout << "这四个数能算出24,其中一种解法为:\n";
                    cout << "(" << "(" << a << p[m] << d << ")" << p[j] << b << ")" << p[i7] << c << "=24" << endl;
                    kinds += 1;
                }
            }
        }
    }
    //第八种顺序
    for (int i8 = 0; i8 < 4; i8++)
    {
        for (int j = 0; j < 4; j++)
        {
            for (int m = 0; m < 4; m++)
            {
                int result = suan24[i8](suan24[j](suan24[m](a, d), c), b);
                if (result == 24)
                {
                    cout << "这四个数能算出24,其中一种解法为:\n";
                    cout << "(" << "(" << a << p[m] << d << ")" << p[j] << c << ")" << p[i8] << b << "=24" << endl;
                    kinds += 1;
                }
            }
        }
    }
    //第九种顺序
    for (int i9 = 0; i9 < 4; i9++)
    {
        for (int j = 0; j < 4; j++)
        {
            for (int m = 0; m < 4; m++)
            {
                int result = suan24[i9](suan24[j](suan24[m](b, d), c), a);
                if (result == 24)
                {
                    cout << "这四个数能算出24,其中一种解法为:\n";
                    cout << "(" << "(" << b << p[m] << d << ")" << p[j] << c << ")" << p[i9] << a << "=24" << endl;
                    kinds += 1;
                }
            }
        }
    }
    //第十种顺序
    for (int i10 = 0; i10 < 4; i10++)
    {
        for (int j = 0; j < 4; j++)
        {
            for (int m = 0; m < 4; m++)
            {
                int result = suan24[i10](suan24[j](suan24[m](b, d), a), c);
                if (result == 24)
                {
                    cout << "这四个数能算出24,其中一种解法为:\n";
                    cout << "(" << "(" << b << p[m] << d << ")" << p[j] << a << ")" << p[i10] << c << "=24" << endl;
                    kinds += 1;
                }
            }
        }
    }
    //第十一种顺序
    for (int i11 = 0; i11< 4; i11++)
    {
        for (int j = 0; j < 4; j++)
        {
            for (int m = 0; m < 4; m++)
            {
                int result = suan24[i11](suan24[j](suan24[m](c, d), a), b);
                if (result == 24)
                {
                    cout << "这四个数能算出24,其中一种解法为:\n";
                    cout << "(" << "(" << c << p[m] << d << ")" << p[j] << a << ")" << p[i11] << b << "=24" << endl;
                    kinds += 1;
                }
            }
        }
    }
    //第十二种顺序
    for (int i12 = 0; i12 < 4; i12++)
    {
        for (int j = 0; j < 4; j++)
        {
            for (int m = 0; m < 4; m++)
            {
                int result = suan24[i12](suan24[j](suan24[m](b, a), c), d);
                if (result == 24)
                {
                    cout << "这四个数能算出24,其中一种解法为:\n";
                    cout << "(" << "(" << b << p[m] << a << ")" << p[j] << c << ")" << p[i12] << d << "=24" << endl;
                    kinds += 1;
                }
            }
        }
    }
    if (kinds == 0)
    {
        cout << "这一组数不能算出24点\n";
    }
    else
        cout << "这组数一共有" << kinds << "种算法\n";
    return 0;
}
2021-01-01 11:30
快速回复:怎么将C++中的开头 # include <iostream> using namespace std; 改成C ...
数据加载中...
 
   



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

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