1.
#include<iostream>
void main() //void表示无return
{
using namespace std;
cout << "Tom" << endl;
cout << "Chengdu" << endl;
}
注:如果遇到VS 2017 运行C++程序时控制台输出窗口一闪而过的问题,那是运行完毕了,不过没来得及显示。对此,可以通过在网上搜教程改vs设置来解决(推荐),也可以在句尾加一条指令system("pause");
2.
#include<iostream>
void main(int Long, int Ma)
{
using namespace std;
cout << "Please input distance in Long;";
cin >> Long; //输入
Ma = 220 * Long;
cout << "Distance in Ma is " << Ma << endl;
//system("pause");
}
3.
#include<iostream>
void f1()
{
using namespace std;
cout << "Three blind mice" << endl;
}
void f2()
{
using namespace std;
cout << "See how they run" << endl;
}
void main()
{
f1();
f1();
f2();
f2();
}
4.
#include<iostream>
void main(int age,int months)
{
using namespace std;
cout << "Please input your age:";
cin >> age;
months = age * 12;
cout << "Your age contains "<<months<<" months.";
}
5.
#include<iostream>
float f(float);
void main(float temp0 ,float temp1)
{
using namespace std;
cout << "Please enter a Celsius value: ";
cin >> temp0;
temp1 = f(temp0);
cout << temp0 << " degrees Celsius is " << temp1 << " degrees Fahrenheit." << endl;
}
float f(float a)
{
return 1.8*a + 32.0;
}
6.
#include<iostream>
void main(double LightYear, double astronomical)
{
using namespace std;
cout << "Enter the number of light years: ";
cin >> LightYear;
astronomical = LightYear * 63240;
cout << LightYear << " light years = " << astronomical << " astronomical units." << endl;
}
7.
#include<iostream>
void main(int hour,int minutes)
{
using namespace std;
cout << "Enter the number of hours: ";
cin >> hour;
cout << "Enter the number of minutes: ";
cin >> minutes;
cout << "Time: " << hour << ":" << minutes;
}