1.编写一个程序,显示您的姓名和地址。
#include<iostream> using namespace std; int main() { char name[20]; cout << "请输入你的姓名: "; cin >> name; cin.get(); cout << "你的姓名是: " << name << endl; char address[40]; cout << "请输入你的地址: "; cin >> address; cin.get(); cout << "你的地址是: " << address << endl; cin.get(); return 0; }
2.输入一个以long为单位的距离,然后将他转化为码(一long 等于220码)
#include<iostream> using namespace std; int main() { int distance_long; cout << "请输入以long为单位的距离,我给您转化为码数: "; cin >> distance_long; cin.get(); int distance_ma; distance_ma = distance_long * 220; cout << "当前距离的码数为: " << distance_ma; cin.get(); return 0; }
4. 让用户输入其年龄,并显示该年龄包含多少个月。
#include<iostream> using namespace std; int main() { int age; cout << "请输入您的年龄: "; cin >> age; cin.get(); int months; months = age * 12; cout << "当前年龄的月数为: " << months; cin.get(); return 0; }
5. 将摄氏温度转化为华氏温度,在main()函数中调用此转换函数,并显示最后的结果;
#include<iostream> using namespace std; int transform_temperature(int temperature); int main() { int Celsius; cout << "Please enter a Celsius value: "; cin >> Celsius; cin.get(); int Fahrenheit; Fahrenheit = transform_temperature(Celsius); cout << Celsius << " degress Celsius is " << Fahrenheit << " degress Fahrenheit." << endl; cin.get(); return 0; } int transform_temperature(int temperature) { temperature = 1.8 * temperature + 32.0; return temperature; }