数组 数组初窥门径我在计算天数,和计算位数的md中都接触了数组 包括可汗大点兵中的数组 所记下来的笔记: 问题: int days_in_month[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; 和 int count[10] = { 0 }; 这两个数组用法有什么不同,这个[]里面和{}的区别与联系 回 2025-11-11
循环嵌套 循环嵌套一、题目求 s = a+aa+aaa+… …+aaa…a的值,其中a是一个数字,如2+22+222+2222,a的值和加数个数n,均从键盘获取。要求a属于[1,9],n小于10(如果不满足此条件,就重新输入)。输入:输入a值和n值输入提示信息:”Please input a:”输入格式:”%d”输入提示信息:”Please input n:”输入格式:”%d” 输出:算式及和输出 2025-11-10
水仙花数 水仙花数一、定义 水仙花数(narcissistic number)也叫“自恋数”,指一个n位数,各位数字的n次幂之和恰好等于它本身。 二、代码实现12345678910111213141516171819#include <stdio.h>#include <math.h>int main() { int a = 100; int gw, sw, bw; do 2025-11-10
输入月份判断天数 输入月份判断天数代码要求 判断闰年 判断大小月 使用switch(我觉得没必要) 代码实现1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950#include <stdio.h>int main(){ int year, month, da 2025-11-10
日历calender 日历calender背景今天做火车回武汉,在车上无聊,想起来老师教的,用C语言写日历,我便试了试。 但是考虑到每月有30天,也有31天的,年还有闰年的,我只写了2025年一月和二月的日历 代码实现1234567891011121314151617181920212223#include <stdio.h>int main() { int year; int i,j=1,g=1 2025-11-10
金字塔 让电脑生成金字塔Pyramid- 老师上课讲过这个代码现在在回武汉的火车上,于是复刻了一下,听课的时候感觉很难,但其实理清楚 - 代码实现12345678910111213141516#include <stdio.h>int main() { int n,i,j,k; scanf_s("%d", &n); for (i = 1;i <= 2025-11-10
可汗大点兵 可汗大点兵妈的,都不想做早操是吧,现在挑出宿舍里面两个人去做操! 代码1这个是王柏森写的代码: 12345678910111213141516171819202122232425262728293031#include <stdio.h>#include <stdlib.h>#include <time.h>int main() { int num; 2025-11-10
生成一个随机数 利用time.h函数生成一个随机数生成一个”随机数”:1234567891011#include <stdio.h>#include <stdlib.h> // 包含rand()、srand()的头文件int main() { int num; num = rand(); printf("%d", num); return 0;}// 2025-11-05
循环中RETRY的用法 循环中RETRY的用法需求:要求用户输入正整数,若输入不合法则重试。 123456789101112131415#include <stdio.h>int main() { int num;RETRY: printf("请输入一个正整数:"); if (scanf("%d", &num) != 1 || nu 2025-11-05
数字字符 数字和数字字符背景今天遇到一个C语言编程题: 要求实现”输入字符并判断是否为数字字符,是则转换为整数,否则输出错误”的功能 我第一次写的代码: 12345678910111213#include <stdio.h>int main(){ char a; printf("please input an digit character:"); 2025-11-05