2的99次方计算机,mooc西交大计算机c++基础题100题(82页)-原创力文档

C++基础题 100 题

第一部分:

1、显示 Hello Worle!

编写 C++程序,在屏幕上显示“Hello World!”。

#include

int main()

{

using namespace std;

cout << "Hello World!" << endl;

return 0;

}

2、显示唐诗

编写 C++程序,在屏幕上显示下列唐诗:

慈母手中线

游子身上衣

临行密密缝

意恐迟迟归

谁言寸草心

报得三春晖

#include

int main()

{

using namespace std;

cout << "慈母手中线\n 游子身上衣\n 临行密密缝\n 意恐迟迟归\n 谁言寸草心\n 报得三春晖" << endl;

return 0;

}

3、显示一句话

编写 C++程序,输入姓名,在屏幕上显示如下格式的文字:

This program is coded by ***.

其中“***”是输入的名字。如输入“ZhangSan”,则显示:

This program is coded by ZhangSan.

注意,姓名中间没有空格,末尾有英文句号。

#include

int main()

{

using namespace std;

char name[50];

cin >> name;

cout << "This program is coded by " << name << '.' << endl;

return 0;

}

4、还是一句话

编写 C++程序,输入姓名,在屏幕上显示如下格式的文字:

This program is coded by ***.

其中“***”是输入的名字。如输入“Zhang San”,则显示:

This program is coded by Zhang San.

注意,姓名中间可能有空格,末尾有英文句号。

#include

int main()

{

using namespace std;

char name[50];

cin.getline(name, 49);

cout << "This program is coded by " << name << "." << endl;

getchar();

return 0;

}

5、计算矩形周长

输入矩形的两个边的长度,计算矩形的周长。

#include

int main()

{

using namespace std;

int a, b, c;

cin >> a >> b;

c = (a + b) * 2;

cout << c << endl;

return 0;

}

6、已知直角边求斜边

输入一个三角形的两个直角边的长度,求其斜边的长度:计算公式是

c=sqrt(a*a+b*b)

其中, a,b 是两个直角边的长度,c 是斜边,sqrt 表示开平方。

#include

#include

int main()

{

using namespace std;

double a, b, c;

cin >> a >> b;

c = sqrt(a*a + b*b);

cout << c << endl;

return 0;

}

第二部分:

1、求过平面上两点的直线的斜率

编写程序,输入平面上的两个点的坐标(x1,y1),(x2,y2),求过这两点的直线的斜率(设斜率不为无穷)。

【提示】数据类型都用 double

#include

int main()

{

using namespace std;

double x1, y1, x2, y2;

double k;

cin >> x1 >> y1 >> x2 >> y2;

k = (y2 - y1) / (x2 - x1);

cout << k << endl;

return 0;

}

2、计算平面上两点之间的距离

编写程序,输入平面上的两个点的坐标(x1,y1),(x2,y2),计算这两点之间的距离。

【提示】数据类型用 double,包含头文件 cmath, 计算公式 distance=(x2-x1)*(x2-x1)+(y2-y1)*(y2-

y1);distance=sqrt(distance);

#include

#include

int main()

{

using namespace std;

double x1, y1, x2, y2;

double k;

cin >> x1 >> y1 >> x2 >> y2;

k = (x2 - x1)*(x2 - x1)

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值