第四章 选择结构程序设计

第四章 选择结构程序设计


##有3个整数,由键盘输入,输出其中最大的数。

#include<stdio.h>
int main()
{int a,b,c,z;
scanf("%d%d%d",&a,&b,&c);
if(a>b) z=a;
else z=b;
else z=c;
printf("max=%d",z);
}

在这里插入图片描述
###从键盘输入一个小于1000的正整数,要求输出它的平方根(如平方根不是整数,则输出其整数部分)。要求在输入数据后先对其检查是否为小于1000的正数。若不是,则要求从新输入。

#include <stdio.h>
#include <math.h>
int main()
{
  int i,k;                                      
  printf("请输入一个小于%d的整数i:",M);
  scanf("%d",&i);
  if (i>1000) 
  {printf("输入的数不符合要求,请重新输入一个小于1000的整数i:\n");
   scanf("%d",&i);
  }
  k=sqrt(i);
  printf("%d的平方根的整数部分是:%d\n",i,k);
  return 0;
}

在这里插入图片描述
####给出一个不多于5位数的正整数;
(1)求出它是几位数;
(2)分别输出每一位数字;
(3)按逆顺序输出各位数,例如原有数为123,应输出321

#include<stdio.h>
main() 
{
    long num;
    printf("输入一个不多于5位的整数:\n");
    scanf("%ld",&num);
    int place;
    if(num>9999) place=5; 
    else if(num>999) place=4; 
    else if(num>99) place=3; 
    else if(num>9) place=2; 
    else place=1;
    printf("\n%d是%d位数\n",num,place);

    int ten_thousand,thousand,hundred,ten,indiv;
    ten_thousand=num/10000;
    thousand=(num-ten_thousand*10000)/1000;
    hundred=(num-ten_thousand*10000-thousand*1000)/100;
    ten=(num-ten_thousand*10000-thousand*1000-hundred*100)/10;
    indiv=(num-ten_thousand*10000-thousand*1000-hundred*100-ten*10);

    printf("\n分别打印出每一位数字和逆序输出:\n");
    switch(place) 
    {
        case 5:printf("%d\t%d%d%d%d%d\n",num,ten_thousand,thousand,hundred,ten,indiv);break;
        case 4:printf("%d\t%d%d%d%d\n",num,indiv,ten,hundred,thousand);break;
        case 3:printf("%d\t%d%d%d\n",num,indiv,ten,hundred);break;
        case 2:printf("%d\t%d%d\n",num,indiv,ten);break;
        case 1:printf("%d\t%d\n",num,indiv);break;
    }
}

运行结果如下:
在这里插入图片描述
#####企业发放的奖金根据企业的当年利润决定。当利润I低于或等于100000元时,奖金可提成10%;利润大于100000元,小于200000元

#include<stdio.h>
main()
{
    long i;
    float bonus,bon1,bon2,bon4,bon6,bon10;
    int c;
    bon1=10000*0.1;
    bon2=bon1+100000*0.075;
    bon4=bon2+200000*0.05;
    bon6=bon4+200000*0.03;
    bon10=bon6+400000*0.015;
    printf("请输入利润i:");
    scanf("%ld",&i);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值