温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

C++程序记录一

发布时间:2020-06-25 16:48:43 来源:网络 阅读:335 作者:herizai 栏目:移动开发
//C++语言的if/else判断语句
#include<iostream>
#include<string>
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<iostream>
#include<vector>
#include<string>
#include<iomanip>
using namespace std;
int main()
{
    vector<int>numb;//使用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<iostream>
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<iostream>//第一种图形
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<iostream>//第二种图形
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<iostream>//第三种图
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");
}


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI