| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1307 人关注过本帖
标题:怎么将C++中的开头 # include <iostream> using namespace std; 改成C语言的 ...
只看楼主 加入收藏
vitozzz
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2020-12-31
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:4 
怎么将C++中的开头 # include <iostream> using namespace std; 改成C语言的开头?
怎么将C++中的开头
# include <iostream>
using namespace std;
改成C语言的开头?
搜索更多相关主题的帖子: std namespace include using C语言 
2020-12-31 10:42
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9031
专家分:54061
注 册:2011-1-18
收藏
得分:0 
仅改个头有什么用?你要说具体的、涉及到这个头的相关函数和代码
2020-12-31 12:45
风过无痕1989
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:8
帖 子:228
专家分:1050
注 册:2020-7-17
收藏
得分:20 
回复 楼主 vitozzz
    stdio 属于 c 语言,开发 c 程序用 stdio,输入输出格式为 printf(),scanf()

     iostream 属于 c++ 语言,开发 c++ 程序可以用 stdio 和 iostream,推荐使用 iostream,输入输出格式为 count<<..,cin>>..

     stdio.h 是 C 的标准 I/O 库,是以函数的方式向 buffer 写入或读取字符。

     iostream 是 C++ 的标准I/O库,引入了输入/输出流的概念,是一个类库,是以类方法从 streambuf 中读取,写入字符。当代码中引入 <iostream> 时,输出需要引用名称空间 std。如果还是按原来 #include <iostream.h> 的方法就会有错。这就是为什么通常用 #include <iostream> 时,要用 using namespace std;。
2020-12-31 15:02
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.019539 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved