c++(003)梯形面积的计算

利用cin输入梯形的上底,下底,和高。定义了3个输入变量。

再定义第4个变量,用于记录梯形的面积,并且把它输出。

 

 1 #include <iostream>
 2 #include <cstdlib>
 3 
 4 using namespace std;
 5 
 6 int main(){
 7     
 8     int a;
 9     int b;
10     int c; 
11     cout<<"梯形的上底是:";
12     cin>>a; 
13     cout<<"梯形的下底是:";
14     cin>>b;
15     cout<<"梯形的高是:" ;
16     cin>>c;
17     int d = (a + b) * c / 2;
18     cout<<"已计算出此梯形的面积为:"<<d; 
19     return 0;
20 }

 

posted @ 2018-02-12 21:30  何婉莹NOIP之路  阅读(1336)  评论(0编辑  收藏  举报