程序代码:
#include <stdio.h> int main() { double r,s1,s2,s3,s4,a,b,h,a1,b1,a2,h2; int i; printf("************数学公式计算**************\n"); printf("1.圆形面积的计算:\n"); printf("2.梯形面积的计算:\n"); printf("3.矩形面积的计算:\n"); printf("4.三角形面积的计算:\n"); printf("请选择要计算什么图形的面积:\n"); scanf("%d",&i); switch (i) { case 1: { printf("圆形面积的计算:\n"); printf("请输入半径r=:"); scanf("%lf",&r); s1=3.14*r*r; printf("圆形面积S=%lf\n",s1); break; } case 2: { printf("梯形面积的计算:\n"); printf("请输入上底a=:"); scanf("%lf",&a); printf("请输入下底b=:"); scanf("%lf",&b); printf("请输入高h=:"); scanf("%lf",&h); s2=(a+b)*h/2; printf("梯形面积S=%lf\n",s2); break; } case 3: { printf("矩形面积的计算:\n"); printf("请输入矩形长a1=:"); scanf("%lf",&a1); printf("请输入矩形宽b1=:"); scanf("%lf",&b1); s3=a1*b1; printf("矩形面积S3=%lf\n",s3); break; } case 4: { printf("三角形面积的计算:\n"); printf("请输入底a2=:"); scanf("%lf",&a2); printf("请输入高h2=:"); scanf("%lf",&h2); s4=a2*h2/2; printf("三角形面积S=%lf",s4); break; } } }