mdl2999_52pj 发表于 2021-5-20 11:06

[学习笔记]C++学习第8天

```
# include <iostream>
# include <array>
// c++17
using namespace std;

int main()
{
        int total{};
        int values[]{2,3,5,7,11,13,17,19,23,29};
        for (auto x:values)
                total += x;
        cout << "total = " << total << endl;
       
        // n!
        cout << "Enter a number named n, let's calculate n! ";
        int n{};
        cin >> n;
       
        auto result{1LL};
       
        if (n<2)
                result =1;
        else
                while(n)
                        result *= n--;
       
        cout << "n!= " << result << endl;
}
```

mdl2999_52pj 发表于 2021-5-20 11:15

```
# include <iostream>
# include <array>
# include <cctype>
//c++17
using namespace std;

int main()
{

        double temp{};
        double total {};
        int count{};
        char reply{};
       
        do{
                cout << "Enter a temerature: ";
                cin >> temp;
                total += temp;
                ++count;
               
                cout << "Do you want to enter another?(y/n): ";
                cin >> reply;
               
        }while(tolower(reply) == 'y');
        cout << "The average temperature is " << total / count << endl;
       
}
```

醒时对人笑 发表于 2021-5-20 15:05

加油加油呀

dysdpf 发表于 2021-5-21 17:35

正在学习,

prochsh 发表于 2021-5-24 11:43

太水了一点,每天学习突出相关语言特性比较好!
页: [1]
查看完整版本: [学习笔记]C++学习第8天