C++程序记录一

//C++语言的if/else判断语句
#include
#include
using namespace std;
int main()
{
    char user_ans;
    cout << "现在正在下雨吗Y/N?" << endl;
    cin >> user_ans;
    if ('Y' == user_ans || 'y' == user_ans)
    {
        cout << "现在正在下雨" << endl;
    }
    else
    {
        cout << "现在没有下雨" << endl;
        cout << "今天会有太阳吗?" << endl;
        cin >> user_ans;
        if ('Y' == user_ans || 'y' == user_ans)
        {
            cout << "今天是晴天" << endl;
        }
        else
            cout << "今天是阴天" << endl;
    }
    system("pause");
}
#include
#include
#include
#include
using namespace std;
int main()
{
    vectornumb;//使用vector
    bool u_agg = true;
    int cnt = 1;
    int buffer;
    float avg;
    char u_ans;
    while (u_agg)
    {
        cout << "第" << cnt << "个数字:\n";
        cin >> buffer;
        numb.push_back(buffer);//vector的push_back()
        cout << "完成没有?Y/N\n";
        cin >> u_ans;
        if ('N' == u_ans || 'n' == u_ans)
        {
            cnt++;
            continue;
        }
        else
        {
            u_agg = false;
        }
                 
    }
    for (int i = 0; i < numb.size() - 2; i++)//size()
        //这段目的可看出来,输入相邻的两个数相加除以3
    {
        int sum = 0;
        for (int j = i; j < i + 2; j++)
            sum = sum + numb[j];
        avg = float(sum) / 3;
        cout << setiosflags(ios::fixed) << setprecision(2) << avg << " \n";
    }
    system("pause");
}
#include
using namespace std;
unsigned long int cnt(int n)//计算n的从0和n的每个数的 阶乘之和
{
    unsigned long int sum = 0;
    for (int i = 1; i<=n; i++)
    {
        unsigned long int mul = 1;
        for (int j = 1; j <= i; j++)
            mul *= j;
        sum += mul;
    }
    return sum;
}
bool pass(int n)//判断输入的n是否在0和25之间
{
    if (n >= 0 && n <= 25)
        return true;
    else
    {
        cout << "n must between 0 and 25!\n";
        return false;
    }
}
int main()
{
    int n;
    unsigned long int sum;
    cout << "enter the number n:";
    cin >> n;
    while (pass(n))
    {
        sum = cnt(n);
        cout << sum;
        break;
    }
    system("pause");
}
#include//第一种图形
using namespace std;
int main()
{
    int j = 0;
    for (int i = 1; i <= 9; i++)
    {
        for (int k = 1; k <= i; k++)
        if ((k + j) % 9)
            cout << (k + j) % 9 << " ";
        else
            cout << 9 << " ";
        cout << endl;
        j = j + i;
    }
    system("pause");
}
#include//第二种图形
using namespace std;
int main()
{
    int j = 0;
    for (int i = 1; i <= 9; i++)
    {
        for (int m = 0; m < 9 - i; m++)
            cout << " ";
        for (int k = 0; k <= i; k++)
        {
            if ((k + j) % 9)
                cout << (k + j) % 9 << " ";
            else
                cout << 9 << " ";
        }
        cout << endl;
        j = j + i;
    }
    system("pause");
}
#include//第三种图
using namespace std;
int main()
{
    int j = 0;
    for (int i = 1; i <= 9; i++)
    {
        for (int k = 1; k <= 8; k++)
        if ((k + j) % 9)
            cout << (k + j) % 9 << " ";
        else
            cout << 9 << " ";
        cout << endl;
        j = j + 8;
    }
    system("pause");
}

当前标题:C++程序记录一
文章转载:http://bzwzjz.com/article/gdodhh.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: H5网站制作 网站设计制作 成都网站设计 app网站建设 成都网站制作公司 做网站设计 成都定制网站建设 定制级高端网站建设 成都网站设计 成都企业网站制作 泸州网站建设 成都响应式网站建设 成都营销网站制作 成都网站制作 成都品牌网站设计 高端网站设计 响应式网站建设 成都网站建设推广 成都网站建设公司 成都网站建设 专业网站设计 成都网站建设