
#include <iostream>
int main()
{
using namespace std;
int x, y;
cout << "Enter x and y: ";
cin >> x >> y;
if (x > y) {
int temp = x;
x = y;
y = temp;
}
int sum = 0;
for (int i = x; i <= y; i++)
sum += i;
cout << x << "和" << y
<< "之间的整数和为"
<< sum << endl;
return 0;
}


#include <iostream>
#include <array>
const int Arsize = 101;
int main()
{
using namespace std;
array<long double, Arsize> fac;
fac[0] = fac[1] = 1;
for (int i = 2; i <= 100; i++)
fac[i] = i * fac[i - 1];
cout << "100! = " << fac[100] << "\n";
return 0;
}

#include <iostream>
int main()
{
using namespace std;
int num;
cout << "Enter a num: ";
cin >> num;
int cursum = 0;
while (num != 0) {
cursum += num;
cout << "Current sum = " << cursum << endl;
cin >> num;
}
cout << "Current sum = " << cursum << endl;
return 0;
}


#include <iostream>
int main()
{
using namespace std;
double Dap = 100, Cleo = 100;
int years = 0;
while (Cleo <= Dap)
{
Dap += 100 * 0.1;
Cleo += Cleo * 0.05;
++years;
}
cout << "After " << years << " years, Cleo exceeds Dap.\n";
cout << "Now Cleo = " << Cleo << ", Dap = " << Dap << endl;
return 0;
}

#include <iostream>
#include <string>
const int Months = 12;
int main() {
using namespace std;
//初始化月份
string months[Months] = {"一月","二月","三月", "四月", "五月", "六月",
"七月", "八月", "九月", "十月", "十一月", "十二月"};
//请求用户输入每月销售额
int volume[Months];
for (int i = 0; i < 12; i++)
{
cout << "输入" << months[i] << "的销售量: " << endl;
cin >> volume[i];
}
//报告这一年的销售情况
int sumsales = 0;
for (int i = 0; i < 12; i++)
sumsales += volume[i];
cout << "今年的销售总量为; " << sumsales << endl;
return 0;
}

#include <iostream>
#include <string>
const int Months = 12;
const int Years = 3;
int main() {
using namespace std;
// 初始化月份
const string months[Months] = { "一月","二月","三月", "四月", "五月", "六月",
"七月", "八月", "九月", "十月", "十一月", "十二月" };
// 请求用户输入每一年每月的销售额
int sales[Years][Months];
for (int year = 0; year < Years; year++) {
for (int month = 0; month < Months; month++) {
cout << "输入第" << year + 1 << "年" << months[month] << "的销售量: ";
cin >> sales[year][month];
}
}
// 报告三年的销售情况
int sumsales[Years] = { 0 };
int totalSales = 0;
for (int year = 0; year < Years; year++) {
for (int month = 0; month < Months; month++) {
sumsales[year] += sales[year][month]; // 计算每年的销售总量
totalSales += sales[year][month]; // 计算总销售量
}
}
for (int year = 0; year < Years; year++) {
cout << "第" << year + 1 << "年的销售总量为: " << sumsales[year] << endl;
}
cout << "三年的销售总量为: " << totalSales << endl;
return 0;
}

#include <iostream>
#include <string>
using namespace std;
struct car {
string make;
int yearmade;
};
int main() {
int carcatlog;
//询问用户汽车数量
cout << "How many cars do you wish to catlog?";
cin >> carcatlog;
//创建car结构体数组
car* mycar_ptr = new car[carcatlog];
//请求用户输入车辆信息
for (int carnum = 0; carnum < carcatlog; carnum++)
{
cout << "Car #" << carnum + 1 << ":\n";
cin.ignore();
cout << "Please enter the make: ";
getline(cin, mycar_ptr[carnum].make);
cout << "Please enter the year made: ";
cin >> mycar_ptr[carnum].yearmade;
}
//输出车辆信息
cout << "Here is your collection:\n";
for (int carnum = 0; carnum < carcatlog; carnum++)
{
cout << mycar_ptr[carnum].yearmade << " " << mycar_ptr[carnum].make << endl;
}
//释放内存
delete[] mycar_ptr;
return 0;
}

#include <iostream>
using namespace std;
const int Max_length = 100;
int main() {
char word[Max_length];
int count = 0;
cout << "Enter words (to stop, type the word done):\n";
while (true)
{
cin >> word;
// 检查用户输入是否为 "done",如果是则退出循环
if (strcmp(word, "done") == 0)
break;
count++;
}
cout << "You entered a total of " << count << " words.\n";
return 0;
}

#include <iostream>
#include <string>
using namespace std;
int main() {
string word;
int count = 0;
cout << "Enter words (to stop, type the word done):\n";
while (true)
{
cin >> word;
// 检查用户输入是否为 "done",如果是则退出循环
if (word == "done")
break;
count++;
}
cout << "You entered a total of " << count << " words.\n";
return 0;
}

#include <iostream>
using namespace std;
int main() {
int rows;
cout << "Enter the number of rows: ";
cin >> rows;
for (int i = 1; i <= rows; ++i) {
// 显示句点填充
for (int j = 1; j <= rows - i; ++j) {
cout << ".";
}
// 显示星号
for (int j = 1; j <= i; ++j) {
cout << "*";
}
cout << endl;
}
return 0;
}