C语言的选择结构,循环结构
发布网友
发布时间:2022-04-23 06:20
我来回答
共1个回答
热心网友
时间:2023-09-19 09:38
1、#include <stdio.h>
void main()
{
int a1,b1,a2,b2;
int c;
printf("默认区间1在区间2的左边。\n");
printf("输入区间1:\n");
scanf("%d %d",&a1,&b1);
printf("输入区间2:\n");
scanf("%d %d",&a2,&b2);
if(b1<a2)
c=-1;
else if(b1==a2)
c=0;
else
c=1;
switch(c)
{
case -1:
printf("交集: Φ\n");
printf("并集: [%d,%d]∪[%d,%d]\n",a1,b1,a2,b2);
printf("差集: [%d,%d]\n",a1,b1);
break;
case 0:
printf("交集: %d\n",b1);
printf("并集: [%d,%d]\n",a1,b2);
printf("差集: [%d,%d]\n",a1,b1-1);
break;
case 1:
printf("交集: [%d,%d]\n",a2,b1);
printf("并集: [%d,%d]\n",a1,b2);
printf("差集: [%d,%d]\n",a1,b1-a2-1);
break;
}
}2、#include <stdio.h>
void main()
{
int wages;
int c;
double tax=0;
printf("请输入工资: ");
scanf("%d",&wages);
c = wages/1000;
printf("税款计算方案: \n");
switch(c)
{
case 0:
tax=0;
printf("%.2f\n",tax);
break;
case 1:
tax = (wages-1000)*0.05;
printf("%d*5%% = %.2f\n",wages-1000,tax);
break;
case 2:
tax = 1000*0.05+(wages-2000)*0.10;
printf("1000*5%% + %d*10%% = %.2f\n",wages-2000,tax);
break;
case 3:
case 4:
tax = 1000*0.05+1000*0.10+(wages-3000)*0.15;
printf("1000*5%% + 1000*10%% + %d*15%%= %.2f\n",wages-3000,tax);
break;
case 5:
default:
tax = 1000*0.05+1000*0.10+2000*0.15+(wages-5000)*0.20;
printf("1000*5%% + 1000*10%% + 2000*15%% + %d*20%%= %.2f\n",wages-5000,tax);
break;
}
}3、#include <stdio.h>
void main()
{
double ChinaGDP=1.0;
double USAGDP=10.0;
double rc=0.08,ra=0.02;
int i=0;
while(ChinaGDP-USAGDP<1e-5)
{
ChinaGDP*=(1+rc);
USAGDP*=(1+ra);
i++;
}
printf("追赶上美国的年份为:%d\n",2000+i);
}4、#include <stdio.h>
#include <math.h>
void main()
{
double ChinaGDP=1.0;
double USAGDP=10.0;
double rc=0.0000,ra=0.02;
USAGDP*=pow(1+0.02,40);
while(ChinaGDP-USAGDP<1e-5)
{
ChinaGDP=1.0;
ChinaGDP*=pow(1+rc,40);
rc+=0.0001;
}
printf("中国经济最低增速: %.2f%%\n",rc*100);}