2023.10.17C语言学习记录

今天学习了分支与循环的一些作业和练习编程题

代码如下:

//#define _CRT_SECURE_NO_WARNINGS 1
//#include<stdio.h>
//#include<string.h>
//#include<math.h>
//#include<stdlib.h>
//#include<time.h>
///*Ctrl+Y取消上一步退回操作
//   Ctrl+D复制光标所在行
//   Ctrl+G跳转到制定
//   Shift+End从头到尾选择
//   Shift+Home从尾到头选择
//   Shift+Ctrl+L删除当前行
//   Ctrl+k Ctrl+C注释光标所在行*/
//void menu() {
//    printf("**********************************************************************\n");
//    printf("****                 1.play                            0.exit                        ****\n");
//    printf("**********************************************************************\n");
//}
//void game() {
//    //1.生成一个随机数
//    int ret = 0;    
//    int guess = 0;//接受猜的数字
//    ret = rand()%100+1;//0~32767-生成1-100之间的随机数
//    //printf("%d\n", ret);
//    //2.猜数字
//    while (1) {
//        printf("猜猜数字:>");
//        scanf("%d", &guess);
//        if (guess > ret) {
//            printf("猜大了\n");
//        }
//        else if (guess < ret) {
//            printf("猜小了\n");
//        }
//        else {
//            printf("恭喜你,才对了!\n");
//            break;
//        }
//    }
//}
//int main(){
//    //猜数字游戏
//    //1.电脑会生成一个随机数
//    // 2.猜数字
//    int input = 0;
//    srand((unsigned int)time(NULL));//拿时间戳来设置随机数生成起始点,time_t time(time_t &timer)
//    do {
//        menu();
//        printf("请选择>:");
//        scanf("%d", &input);
//        switch (input) {
//        case 1:
//            game();//猜数字游戏
//            break;
//        case 0:
//            printf("退出游戏\n");
//            break;
//        default:
//            printf("选择错误\n");
//            break;
//        }
//    } while (input);
                                                                                编程题9:乘法口诀表;在屏幕上输出9*9乘法口诀
                                                                                //int i = 0;
                                                                                确定打印9行
                                                                                //for (i = 1; i <=9; i++) {
                                                                                //    int j;//打印一行
                                                                                //    for (j = 1; j <= i; j++) {
                                                                                //        printf("%d*%d=%d\t", i, j, i * j);
                                                                                //    }
                                                                                //    printf("\n");
                                                                                //}
                                                                                //return 0;
                                                编程题8:求最大数;内容:求10个整数中最大值
                                                //int arr[] = { -1,2,3,4,5,6,7,8,9,10 };
                                                //int max = arr[0];//最大值
                                                //int i = 0;
                                                //int sz = sizeof(arr) / sizeof(arr[0]);
                                                //for (i = 1; i < sz; i++) {
                                                //    if (arr[i] > max) {
                                                //        max = arr[i];
                                                //    }
                                                //}
                                                //printf("max=%d\n", max);
                                                //return 0;
                                                                                        编程题7:分数求和;计算1/1-1/2+1/3-1/4+1/5......+1/99-1/100
                                                                                        //int i = 0;
                                                                                        //double sum = 0.0;
                                                                                        //int flag = 1;
                                                                                        //for (i = 1; i <= 100; i++) {
                                                                                        //    sum += flag*1.0 / i;
                                                                                        //    flag = -flag;
                                                                                        //}
                                                                                        //printf("sum=%lf", sum);
                                                                                        //return 0;
                                                            编程题6:数9的个数;内容:编程写一下1到100的所有整数中出现多少个数字9
                                                            //int i = 0;
                                                            //int count = 0;
                                                            //for (i = 1; i <= 100; i++) {
                                                            //    if (i %10== 9) {
                                                            //        count++;
                                                            //    }
                                                            //    if (i / 10 == 9) {
                                                            //        count++;
                                                            //    }
                                                            //}
                                                            //printf("count=%d ", count);
                                                            //return 0;
                                                            //                                          /*int a = 0;
                                                                                                        /*    int b = 0;
                                                                                                            for (a = 1, b = 1; a <= 100; a++) {
                                                                                                                if (b >= 20) {
                                                                                                                    break;
                                                                                                                }
                                                                                                                if (b % 3 == 1){
                                                                                                                    b = b + 3;
                                                                                                                    continue;
                                                                                                                }
                                                                                                                b = b - 5;
                                                                                                            }
                                                                                                            printf("%d\n", a);
                                                                                                            return 0;*/

                                                                        编程题5:打印素数;内容:打印100-200之间的素数
                                                                        //int i = 0;
                                                                        //int count=0;//计数变量
                                                                        ///*int j = 0;*/
                                                                        //for (i= 101; i<= 2000000; i+=2) {//试除法2~i-1
                                                                        //    int j;
                                                                        //    for (j = 2; j < sqrt(i); j++) {
                                                                        //        if (i % j == 0) {
                                                                        //            break;
                                                                        //        }
                                                                        //    }
                                                                        //    if (j>sqrt(i)) {
                                                                        //        count++;
                                                                        //        printf("%d ", i);
                                                                        //    }
                                                                        //}
                                                                        //printf("\ncount=%d\n", count);
                                                                        //return 0;
                                编程题4:打印闰年;内容:打印1000年到2000年之间的闰年
                                //int year = 0;
                                //int count = 0;
                                //for (year = 1000; year <= 2000; year++) {
                                //    //判断year是否为闰年
                                //    //1.能被4整除而且不能被100整除的是闰年
                                //    //2.能被400整除的是闰年
                                //    if ((year % 4 == 0 && year % 100 != 0)|| year % 400 == 0) {
                                //        printf("%d\t", year);
                                //        count++;
                                //    }
                                ///*    else if (year % 400 == 0) {
                                //        printf("%d", year);
                                //        count++;
                                //    }*/
                                //}
                                //printf("\ncount=%d\n", count);
                                //return 0;
                                                                        编程题3:最大公约数;内容:给定两个数,求这两个数的最大公约数
                                                                        辗转相除法
                                                                        //int m = 24;
                                                                        //int n = 18;
                                                                        //int r=0;
                                                                        //scanf("%d %d", &m, &n);//m>n
                                                                        //while (r=m % n) {
                                                                        //    //r = m % n;
                                                                        //    m = n;
                                                                        //    n = r;
                                                                        //}
                                                                        //printf("%d\n", n);
                                                                        //return 0;
                            编程题2:打印3的倍数的数;内容:写一个代码打印1-100之间所有的3的倍数
                            //int i = 0;
                            //for (i = 1; i <= 100; i++) {
                            //    if (i %3 == 0) {
                            //        printf("%d\t", i);
                            //    }
                            //}
                            //return 0;
                                            编程题1:从大到小输出
                                            //int a = 0;
                                            //int b = 0;
                                            //int c = 0;
                                            //scanf("%d %d %d", &a, &b, &c);//2 1 3
                                            判断大小a>b>c
                                            //if (a < b) {
                                            //    int tmp=a;
                                            //    a = b;
                                            //    b = tmp;
                                            //}
                                            //if (a < c) {
                                            //    int tmp = a;
                                            //    a = c;
                                            //    c = tmp;
                                            //}
                                            //if (b < c) {
                                            //    int tmp = b;
                                            //    b = c;
                                            //    c = tmp;
                                            //}
                                            //printf("%d %d %d\n", a, b, c);
                                            //return 0;


                                                                                                            /*    int x = 3;
                                                                                                                int y = 3;
                                                                                                                switch (x % 2) {
                                                                                                                case 1:
                                                                                                                    switch (y) {
                                                                                                                    case 0:
                                                                                                                        printf("first");
                                                                                                                    case 1:
                                                                                                                        printf("second");
                                                                                                                        break;
                                                                                                                    default:printf("hello");
                                                                                                                    }
                                                                                                                case 2:
                                                                                                                    printf("third");
                                                                                                                }
                                                                                                                return 0;            */                                            
                                                                      /*int b;
                                                                    switch (2) {
                                                                    case 1:b = 30;
                                                                    case 2:b = 20;
                                                                    case 3:b = 16;
                                                                    default:b = 114514;
                                                                    }
                                                                    printf("%d\n", b);
                                                                    return 0;*/
            /*int i = 0;
            for (i = 0; i < 10; i++) {
                if (i = 5) {
                    printf("%d", i);
                }
            }
            return 0;*/
//} 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值