1、
代码:
#include<iostream>
int main()
{
using namespace std;
cout << "My name : guugle" << endl;
cout << "My address : China Shenzhen" << endl;
return 0;
}
运行结果:
2、
代码:
#include<iostream>
int main()
{
using namespace std;
cout << "请输入尺寸:";
int lang;
cin >> lang;
lang = 220 * lang;
cout << "转换成码为:" << lang <<endl;
return 0;
}
运行结果:
3、
代码:
#include<iostream>
using namespace std;
void functionA();
void functionB();
int main()
{
functionA();
functionA();
functionB();
functionB();
return 0;
}
void functionA()
{
cout << "Three blind misc";
cout << endl;
}
void functionB()
{
cout << "See how they Run";
cout << endl;
}
运行结果:
4、
代码:
#include<iostream>
using namespace std;
void hua(int);
int main()
{
cout << "Please enter a Celsius value:";
int wendu;
cin >> wendu;
hua(wendu);
return 0;
}
void hua(int wendu)
{
double huadu = 1.8 * wendu + 32.0;
cout << wendu << "degrees Velsius is " << huadu << "degrees Fahrenheit" << endl;
}
运行结果:
5、
代码:
#include<iostream>
using namespace std;
double lightyear(double);
int main()
{
cout << "Enter the number of light years:";
double years;
cin >> years;
double lyear = lightyear(years);
cout << years <<"light years = " << lyear << "astronomical units.";
cout << endl;
return 0;
}
double lightyear(double years)
{
return years * 63240;
}
运行结果:
6、
代码:
#include<iostream>
using namespace std;
void showTime(int, int);
int main()
{
cout << "请输入小时:";
int hours;
cin >> hours;
cout << "请输入分钟数:";
int minutes;
cin >> minutes;
showTime(hours, minutes);
return 0;
}
void showTime(int hours, int minutes)
{
cout << "Time:" << hours <<":" << minutes << endl;
}
运行结果:

本文通过六个实例演示了C++的基本语法和编程技巧,包括简单的输出个人信息、尺寸转换、函数调用、温度单位转换、光年到天文单位的转换以及显示时间。
33万+

被折叠的 条评论
为什么被折叠?



