天天看點

藍橋杯 算法訓練 三角形面積

問題描述

  給你一個三角形的底邊長度a以及三角形的高度h,求此三角形面積s。

輸入格式

  輸入的第一行包含兩個整數a, h,三角形的底邊長a和高h。

輸出格式

  輸出三角形的面積。

樣例輸入

2 2

樣例輸出

2

資料規模和約定

  0<a,b<100000

注:有a*h不是偶數的情況,故需要保留一位小數點。

#include<iostream>
#include<cstdio>
using namespace std;

int main(){
	int a, h, s;
	scanf("%d %d", &a, &h);
	s=a*h;
	if(s%2==0){
		printf("%d", s/2);
	} 
	else{
		printf("%.1f", s/2.0);
	}
	return 0;
}
           

繼續閱讀