2022.4.26

/* 2022.4.26*/
/* rabnud 博士加入了一个社交圈,起初它有5个朋友,他注意到他的朋友以下面的方式
   增长,第一周少了1个朋友,剩下的朋友数量翻倍,第2周少了两个朋友,剩下的朋友
    数量翻倍,*/
/* 编程分析 :在该程序中, rabund 朋友圈的算法可以表述为2X(朋友数-周数),朋友
   数的起始值为5,为了计算何时达到邓巴数,应使用不定次循环,循环入口条件设置
    为朋友数小数邓巴数。完整代码如下:*/
//#include <stdio.h>
//#include <string.h>
//int main()
//{
//    int rabnud = 5;
//    int weeks = 1;
//    while (rabnud < 150)
//    {
//        printf("at %d weeks has %4d friends \n", weeks, rabnud);
//        rabnud = 2 * (rabnud - weeks++);
//        /*计算每周rabnud 博士的朋友数 */
//    };
//    printf("\ndone!\n");
//    return 0;
//}

/* C控制语句,分支和跳转*/
/* 找出colddays.c -- 找出0(摄氏度)C以下的的天数占总天数的百分比 */


//#include <stdio.h>
//int main()
//{
//    const int FREEZING = 0;        /* 零度 界限值 */
//    float temperature;            /*   温度值 */ 
//    int cold_days = 0;
//    int all_days = 0;
//
//    printf("enter the list of daily low temperatutes.\n");
//        printf("use celsius, and enter q to quit.\n");
//        while (scanf("%f", &temperature) == 1)
//        {
//            all_days++;
//          /*  if 语句是一个条件判断语句 */ 
//            if (temperature < FREEZING)
//                cold_days++;
//        }
//        if (all_days != 0)
//            printf("%d days total: %.1f%% were below freezing.\n", all_days, 100.0 * (float)cold_days / all_days);
//        if (all_days == 0)
//            printf("no data entered!\n");
//
//    return  0;
//}
//enter the list of daily low temperatutes.
//use celsius, and enter q to quit.
//12 5 - 2.5 0 6 8 - 3 - 10 5 10 q
//10 days total : 30.0 % were below freezing.
//输入每天的低温列表。
//使用摄氏度,输入q退出。
//12 5 - 2.5 0 6 8 - 3 - 10 5 10 q
//10天合计 : 30.0 % 低于冰点。


/* cypherl.c -- 更改输入,空格不变 */
//#include <stdio.h>
//#define SPACE ' '                  /* SPACE 表示单引号 - 空格 - 单引号 */
//int main()
//{
//    char ch;
//
//    ch = getchar();         /* 读取一个字符 */
//    while (ch != '\n')           /* 当一行结束时*/
//    {
//        if (ch == SPACE)       /* 留下空格 */
//            putchar(ch);       /* 该字符不变 */
//        else
//            putchar(ch + 1);   /* 改变其它字符 */     /* 65 + 1 == 66 --> 'B'*/
//        ch = getchar();           /* 获取下一个字符*/    /* A 之后 按了一下 enter ---'\n'*/
//
//     }
//    putchar(ch);     /* 打印换字符*/
//
//    return 0;
//}


     /*  cypher2.c -- 替换输入的字母, 非字母字符保持不变 */
//#include <stdio.h>
//#include <ctype.h>          /* 包含 isalpha ()的函数原型 */
//int main()
//{
//    char ch;
//
//    while ((ch = getchar()) != '\n')
//    {
//        if (isalpha(ch))        /* 如果是一个字符 */
//            putchar(ch + 1);       /* 显示该字符的下一个字符 */
//        else                   /* 否则 */
//            putchar(ch);   /* 原样显示 */
//    }
//    putchar(ch);            /* 显示换行符 */
//
//        return 0;
//
//}

/* electric.c -- 计算电费-----------------------------------------------------------------------------------------------------------------不对 */
#include <stdio.h>
#define RATE1   0.13230                 /*  首次使用360 kwh 的费率 */
#define RATE2   0.15040                /*  首次使用108 kwh 的费率 */
#define RATE3   0.30025                /*  首次使用252 kwh 的费率 */
#define RATE4   0.34025                 /*  首次使用720 kwh 的费率 */
#define BREAK1   360.0                    /* 费率的第一个分解点 */
#define BREAK2   468.0                    /* 费率的第二个分解点 */
#define BREAK3   720.0                    /* 费率的第三个分解点 */
#define BASE1  (RATE1 * BREAK1)           /* 使用 360 kwh 的费用 */
#define BASE2  (BASE1 + (RATE2 * (BREAK2 - BREAK1)))        /* 使用 468 kwh 的费用 */
#define BASE3  (BASE2 + (RATE3 * (BREAK3 - BREAK2)))        /* 使用720 kwh 的费用 */
int main()
{
    double kwh;                       /* 使用的千瓦时 */
    double bill;                     /* 电费 */

    printf("please enter the kwh used.\n");
    scanf("%lf", &kwh);             /* %lf 对应double 类型 */
    if (kwh <= BREAK1);
    bill = RATE1 * kwh;
    else if (kwh <= BREAK2)        /* 360~468  kwh      */
        bill = BASE1 + (RATE2 * (kwh - BREAK1));
    else if (kwh <= BREAK3)                 /* 468~720 kwh */
        bill = BASE2 + (RATE3 * (kwh - BREAK2));
    else                                  /* 超过720 kwh */
        bill = BASE3 + (RATE4 * (kwh - BREAK3));
    printf("the charge for %.1f kwh is $1.2f.\n", kwh, bill);

    return 0;
}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值