c語言練習題 3-2 計算矩形面積
阿新 • • 發佈:2019-01-30
矩形面積計算
#include<stdio.h> int max(int a,int b) { if(a>b) { return a; } else { return b; } } int min(int a,int b) { if(a<b) { return a; } else { return b; } } int main() { int Ax1,Ay1,Ax2,Ay2; int Bx1,By1,Bx2,By2; int a,b,right,left,top,buttom; scanf("%d %d %d %d",&Ax1,&Ay1,&Ax2,&Ay2); scanf("%d %d %d %d",&Bx1,&By1,&Bx2,&By2); a=max(Ax1,Ax2); b=max(Bx1,Bx2); right=min(a,b); a=min(Ax1,Ax2); b=min(Bx1,Bx2); left=max(a,b); a=max(Ay1,Ay2); b=max(By1,By2); top=min(a,b); a=min(Ay1,Ay2); b=min(By1,By2); buttom=max(a,b); if(((right-left)<=0)||((top-buttom)<=0)) { printf("0"); } else { printf("%d\n",(right-left)*(top-buttom)); } return 0; }