2022.4.15

该博客包含三个C语言编程示例:一是创建高尔夫锦标赛记分卡,展示三名选手的初始分数;二是计算1到20的平方值;三是模拟棋盘上的指数增长,探讨世界小麦产量与棋盘方格的关系。通过这些示例,读者可以了解基本的C语言编程技巧和数学概念的应用。
摘要由CSDN通过智能技术生成

2022.4.15
///* golf.c -- 高尔夫锦标赛记分卡 */
//#include <stdio.h>
//int main()
//{
//    int jane, tarzan, cheeta;    //简,人猿泰山,猎豹;
//
//    cheeta = tarzan = jane = 68;Cheeta =泰山= Jane = 68;
//    printf("                cheeta tarzan   jane\n");//
//    printf("First round score %4d %8d %8d\n", cheeta, tarzan, jane);//printf(“第一轮得分%4d %8d %8d\n”,cheeta, tarzan, jane);  
//
//    return 0;
//}
cheeta tarzan   jane
First round score   68       68       68
cheeta泰山简
第一轮得分68 68 68


///* squares.c -- 计算 1-20 的平方 */
//#include <stdio.h>
//int main()
//{
//    int num = 1;
//
//    while (num < 21)
//    {
//        printf("%4d %6d\n", num, num * num);
//        num = num + 1;
//    }
//    return 0;
//}
//
///* wheat.c -- 指数增长 */
//#include <stdio.h>
//#define SQUARES 64  //棋盘中的方格数
//int main()
//{
//    const double CROP = 2E16;    //世界小麦年产谷粒数
//    double current, total;      //目前,总;
//    int count = 1;
//
//    printf("square     grains  total    ");
//    printf("fraction  of  \n");
//    printf("      added          grains     ");
//    printf("world total\n");  //printf("世界总\ n ");
//    total = current = 1.0;    /*  从1颗谷粒开始  */
//    printf("%4d %13.2e %12.2e %12.2e\n", count, current, total, total / CROP);
//    
//    while (count < SQUARES)
//    {
//        count = count + 1;
//        current = 2.0 * current;    //下一个方格谷粒翻倍
//        total = total + current;    /*  跟新总数 */
//        printf("%4d %13.2e %12.2e %12.2e\n", count, current, total, total / CROP);
//    }
//    printf("That`s all.\n");
//
//    return 0;
//}

/* divide.c -- 演示除法 */
//#include <stdio.h>
//int main()
//{
//    printf("integer division:  5/4 is %d \n", 5 / 4);
//    printf("integer division:  6/3 is %d \n", 6 / 3);
//    printf("integer division:  7/4 is %d \n", 7 / 4);
//    printf("floating division:  7./4 is %1.2f \n", 7. / 4);
//    printf("mixed division:  7./4 is %1.2f \n", 7. / 4);
//
//    return 0;
//}


/* rules.c -- 优先级测试 */
//#include <stdio.h>
//int main()
//{
//    int top, score;
//
//    top = score = -(2 + 5) * 6 + (4 + 3 * (2 + 3));
//    printf("top = %d, score = %d\n", top, score);
//
//    return 0;
//}
//


sizeof.c -- 使用 sizeof 运算符
//#include <stdio.h>
//int main()
//{
//    int n = 0;
//    size_t intsize;
//
//    intsize = sizeof(int);
//    printf("n = %d, n has %zd bytes; all ints have %zd bytes.\n", n, sizeof n, intsize);
//    return 0;
//}
n = 0, n has 4 bytes; all ints have 4 bytes.
N = 0, N有4个字节; 所有的整数都有4个字节。


 min_sec.c -- 把秒数转换成分和秒
//#include <stdio.h>
//#define SEC_PER_MIN 60    // 1分钟60秒
//int main()
//{
//    int sec, min, left;
//    printf("Convert seconds to minutes and seconds!\n");//printf("将秒转换为分钟和秒! ");  
//    printf("Enter the number of seconds (<=0 to quit):\n");//printf("输入秒数(<=0退出):\n");  
//    scanf("%d", &sec);    // 读取秒数
//    while (sec > 0)
//    {
//        min = sec / SEC_PER_MIN;  //截断分钟数
//        left = sec % SEC_PER_MIN;   //  剩下的秒数
//        printf("%d seconds is %d minutes, %d seconds.\n", sec, min, left);//Printf ("%d seconds is %d minutes, %d seconds. ")。 \n",秒,分钟,左);  
//        printf("Enter next value (<=0 to quit):\n");//printf("输入下一个值(<=0退出):\n");  
//        scanf("%d", &sec);
//    }
//    printf("Done!\n");
//
//    return 0;
//}
Convert seconds to minutesand seconds!
Enter the number of seconds(<= 0 to quit) :
    2500
    2500 seconds is 41 minutes, 40 seconds.
    Enter next value(<= 0 to quit) :
    将秒转换为分钟和秒!
    输入退出的秒数(<= 0) :
    2500
    2500秒等于41分40秒。
    输入下一个值(<= 0退出) :

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值