C++代码练习(1)
//1. 输入长方形的长和宽,求长方形的周长和面积。
//2. 从键盘输入一个负整数,求出它的绝对值并输出。
//3. 编写一个C++程序,输出以下信息:
//* ************************
//Very Good!
//*************************
//4. 编写一个程序,已知三角形的三条边a、b、c的值为3、4、5,求出它的周长并输出。
//5. 编写一个程序,已知半径和高的值分别为3和5,输出圆柱体的底面积和体积
#include <iostream>
using namespace std;
/*
int main()
{
system("pause");
return 0;
}
*/
/*
int main()
{
int a, b;
cout << "请输入长方形的长";
cin >> a;
cout << "请输入长方形的宽";
cin >> b;
cout << "长方形的周长=" << 2 * a + 2 * b << endl;
cout << "长方形的面积=" << a * b << endl;
system("pause");
return 0;
}
*/
/*
int main()
{
int a;
cout << "请输入一个负数" << endl;
while (1)
{
cin >> a;
if (a > 0)
cout << "输入违法数,请重新输入"<<endl;
else
break;
}
a = a * -1;
cout << "这个数的绝对值是\t" << a<<endl;
system("pause");
return 0;
}
*/
/*
#include <iomanip>
int main()
{
cout << "*************************" << endl << setw(18) << "Very Good!" << endl << "*************************" << endl;
system("pause");
return 0;
}
*/
/*
int main()
{
int a, b, c;
a = 3; b = 4; c = 5;
cout << "已知三角形的三条边为" << a <<"," << b << "," << c << endl
<< "那么三角形的周长为" << a + b + c << endl;
system("pause");
return 0;
}
*/
/*
int main()
{
int r, h;
r = 3; h = 5;
cout << "圆柱体的底面半径为" << r << "圆柱体的高为" << h << endl;
cout << "圆柱的底面积为" << 3.14 * r * r << endl;
cout << "圆柱的底面积为" << 3.14 * r * r * h << endl;
system("pause");
return 0;
}
*/