#include
using namespace std;
int main()
{
cout << "hello,word\n";
return 0;
}
查找int的空间大小
#include
using namespace std;
int main()
{
cout << "The size of an int is :\t\t" << sizeof(int) << "bytes.\n";
return 0;
}
定义枚举类型,输出比赛结果
#include
using namespace std;
enum GameResult {WIN,LOSE,TIE,CANCEL};
int main()
{
GameResult result;
enum GameResult omit = CANCEL;
for (int count = WIN; count <= CANCEL; count++) {
result = GameResult(count);
if (result == omit)
cout << "The game was cancelled" << endl;
else {
cout << "The game was played";
if (result == WIN) cout << "and we won";
if (result == LOSE) cout << "and we lost";
cout << endl;
}
}
return 0;
}
#include
using namespace std;
int main()
{
int i = 1, sum = 0;
do { sum += 1;
i++;
} while (i <= 10);
cout << "sum=" << sum << endl;
return 0;
}
//计算圆形,正方形,矩形的面积,运行时先提示用户选择图形类型,
//然后对图形要求用户输入半径值,对长方形要求用户输入长和宽的值,
//对正方形要求用户输入边长的值,计算面积的值然后显示出来。
#include
using namespace std;
const float PI = 3.1416;
int main()
{
int iType;
float radius, a, b, area;
cout << "图形的类型为?(1-圆形 2-正方形 3-圆):";
cin >> iType;
switch(iType)
{
case 1:
cout << "圆的半径:";
cin >> radius;
area = PI*radius*radius;
cout << "面积为:" << area << endl;
break;
case 2:
cout << "矩形的长为:";
cin >> a;
cout << "矩形的宽为:";
cin >> b;
area = a*b;
cout << "面积为:" << area << endl;
break;
case 3:
cout << "正方形的半径:";
cin >> a;
area = a*a;
cout << "面积为:" << area << endl;
break;
default:
cout << "不是合法输入值"<
#include "iostream"
using namespace std;
struct MytimeStruce
{
unsigned int year;
unsigned int month;
unsigned int day;
unsigned int hour;
unsigned int min;
unsigned int sec;
};
int main()
{
MytimeStruce mytime = { 2017,11,22,18,45,58 };
cout << "please input year:" << endl;
cin >> mytime.year;
cout << "please input month:" << endl;
cin >> mytime.month;
cout << "please input day:" << endl;
cin >> mytime.day;
cout << "please input hour:" << endl;
cin >> mytime.hour;
cout << "please input min:" << endl;
cin >> mytime.min;
cout << "please input sec:" << endl;
cin >> mytime.sec;
cout << "the time is set to:" << mytime.year << "/";
cout << mytime.month << "/";
cout << mytime.day << " ";
cout << mytime.hour << ":";
cout << mytime.min << ":";
cout << mytime.sec << endl;
return 0;
}
#include "iostream"
using namespace std;
double power(double x, int n) {
double val = 1.0;
while (n--)
val *= x;
return val;
}
int main()
{
double pow;
pow = power(5, 2);
cout << "5 to the power 2 is " << pow << endl;
return 0;
}
#include "iostream"
using namespace std;
int fun2(int m) {
return m*m;
}
int fun1(int x, int y) {
return fun2(x) + fun2(y);
}
int main()
{
int a, b;
cout << "Please enter two integers(a and b):";
cin >> a >> b;
cout << "The sum of square of a and b :" << fun1(a, b) << endl;
return 0;
}
//输入两个整数交换后输出
#include "iostream"
using namespace std;
void swap(int &a, int &b) {
int t = a;
a = b;
b = t;
}
int main()
{
int x = 5, y = 10;
cout << "x=" << x << "y=" << y <
#include "iostream"
using namespace std;
const double PI = 3.14159265358979;
inline double calArea(double radius) {
return PI*radius*radius;
}
int main()
{
double r = 3.0;
double area = calArea(r);
cout << area << endl;
return 0;
}
#include "iostream"
using namespace std;
float Convert(float F){
float C;
C = (F - 32) * 5 / 9;
return C;
}
int main()
{
float F;
cout << "Please input the temperature in fahrenheit:\n";
cin >> F;
cout << "Conver the temperature in celsius:\n";
cout << Convert(F);
return 0;
}