C语言复习
在C++的海洋里挣扎
路漫漫其修远兮,吾将上下而求索
展开
-
题目:海滩上有一堆桃子,五只猴子来分。第一只猴子把这堆桃子平均分为五份,多了一个,这只猴子把多的一个扔入海中,拿走了一份。第二只猴子把剩下的桃子又平均分成五份,又多了一
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <string.h>/* 题目:海滩上有一堆桃子,五只猴子来分。第一只猴子把这堆桃子凭据分为五份,多了一个,这只 猴子把多的一个扔入海中,拿走了一份。第二只猴子把剩下的桃子又平均分成五份,又多了 一个,它同样把多的一个扔入海中,拿走了一份,第三、第四、第五只猴子都是这样做的, .原创 2020-06-07 20:38:22 · 2480 阅读 · 0 评论 -
题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少?
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <string.h>/* 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月 后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? 提示:程序分析: 兔子的规律为数列1,1,2,3,5,8,13,21....*/int main(){.原创 2020-06-07 20:36:46 · 1345 阅读 · 0 评论 -
题目:809*??=800*??+9*??+1 其中??代表的两位数,8*??的结果为两位数,9*??的结果为3位数。求??代表的两位数,及809*??后的结果。
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <string.h>/* 题目:809*??=800*??+9*??+1 其中??代表的两位数,8*??的结果为两位数, 9*??的结果为3位数。求??代表的两位数,及809*??后的结果。*/int main(){ int n, flag = 0; for (n = 10; n <= .原创 2020-06-07 20:35:52 · 2133 阅读 · 3 评论 -
题目:八进制转换为十进制
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>/* 题目:八进制转换为十进制 八进制456 =》 十进制 302 302 = 6*pow(8,0)+5*pow(8,1)+4*pow(8,2)*/int main07(){ int n; scanf_s("%d", .原创 2020-06-07 20:35:16 · 2076 阅读 · 0 评论 -
题目:求0—7所能组成的奇数个数。 (不可重复 0不能做首位) 46972
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <string.h>/* 题目:求0—7所能组成的奇数个数。 (不可重复 0不能做首位) 46972 0,1,2,3,4,5,6,7 一位:4 两位:4*6 三位:4*7*6-4*6 -> 4*6*6 四位:4*7*6*5-4*6*5 -> 4*6*6*5 五位:.原创 2020-06-07 20:33:33 · 733 阅读 · 0 评论 -
两个字符串(“hello ”,“thundersoft !”)连接程序
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <string.h>/* 两个字符串(“hello ”,“thundersoft !”)连接程序*/int main(){ /*char* str1 = "hello "; char* str2 = "thundersoft!"; char str3[50] = ""; int i = .原创 2020-06-07 20:32:59 · 212 阅读 · 0 评论 -
题目:判断一个素数能被几个9整除
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>/* 题目:判断一个素数能被几个9整除*/int main(){ int a, count = 0; scanf_s("%d", &a); for (int i = 2; i < sqrt(a); i++) .原创 2020-06-07 20:31:34 · 356 阅读 · 0 评论 -
题目:计算字符串中子串出现的次数 提示:请使用scanf 函数输入2个字符串str1, str2 ,再计算字符串中子串出现的次数
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <string.h>/* 题目:计算字符串中子串出现的次数 提示:请使用scanf 函数输入2个字符串str1, str2 ,再计算字符串中子串出现的次数*/int main03(){ char str1[100]; char str2[50]; int m_count = 0; sca.原创 2020-06-07 20:31:03 · 1203 阅读 · 2 评论 -
题目:从键盘输入一个字符串,将小写字母全部转换成大写字母,然后输出到一个磁盘文件“test”中保存。输入的字符串以!结束。
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <string.h>/* 题目:从键盘输入一个字符串,将小写字母全部转换成大写字母,然后输出到一个磁盘文件“test”中保存。 输入的字符串以!结束。*/int main(){ char buf[100] ; int i = 0; FILE* f_write = fopen("test.原创 2020-06-07 20:30:32 · 6669 阅读 · 1 评论 -
题目:有两个磁盘文件A和B,各存放一行字母,要求把这两个文件中的信息合并(按字母顺序排列), 输出到一个新文件C中
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <string.h>/* 题目:有两个磁盘文件A和B,各存放一行字母,要求把这两个文件中的信息合并(按字母顺序排列), 输出到一个新文件C中*/int cmp(const void* a, const void* b){ return *(char*)a - *(char*)b;}.原创 2020-06-07 20:29:45 · 4828 阅读 · 0 评论 -
输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <string.h>/* 输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。*/int main10(){ char c; int letter = 0, space = 0, digit = 0, other = 0; while ((c = getchar())!='.原创 2020-05-30 16:14:05 · 1304 阅读 · 0 评论 -
打印菱形
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <string.h>/* 打印出如下图案(菱形) * *** ***** ******* ***** *** **/int main(){ int row = 7, col = 7; //可改成键盘输入 for (int i .原创 2020-05-30 16:13:22 · 121 阅读 · 0 评论 -
求s=a+aa+aaa+aaaa+aa...a的值,其中a是一个数字。例如2+22+222+2222+22222(此时共有5个数相加),几个数相加有键盘控制。
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <string.h>/* 求s=a+aa+aaa+aaaa+aa...a的值,其中a是一个数字。例如2+22+222+2222+22222(此时共有5个数相加),几个数相加有键盘控制。*/int main(){ int n, a; scanf_s("%d %d", &a, &n.原创 2020-05-30 16:01:02 · 285 阅读 · 0 评论 -
输入某年某月某日,判断这一天是这一年的第几天?
#define _crt_secure_no_warnings#include <stdio.h>#include <stdlib.h>#include <string.h>/* 输入某年某月某日,判断这一天是这一年的第几天?*/int getdays(int m, int d, int x){ if (m == 1) return d; if (m == 2) return 31 + d; int days = 0; m = .原创 2020-05-30 16:00:30 · 306 阅读 · 0 评论 -
定义一个字符串“hello world!”,并实现字符串反转后打印出来。
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <string.h>/* 定义一个字符串“hello world!”,并实现字符串反转后打印出来。*/int main(void){ char* c = "hello world"; int len = strlen(c); for (int i = len - 1; i >= 0;.原创 2020-05-30 15:59:44 · 2784 阅读 · 0 评论 -
向有序数组中插入一个数,使其原有顺序不变
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <string.h>/* 有一个已经排好序的数组a[11]={1,4,6,9,13,16,19,28,40,100}; 现输入一个数15,要求按原来的规律将它插入数组中。*/void insert_array(int* a, int len, int e){ //printf("%d\n", a.原创 2020-05-30 15:59:13 · 3095 阅读 · 0 评论 -
求一个3*3矩阵对角线元素之和
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <string.h>/* 求一个3*3矩阵对角线元素之和*/int main(void){ int a[3][3]; int sum = 0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { .原创 2020-05-30 15:55:50 · 1736 阅读 · 1 评论 -
编写一个函数,输入n为偶数时,调用函数求1/2+1/4+...+1/n, 当输入n为奇数时,调用函数1/1+1/3+...+1/n(利用指针函数)
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <string.h>/* 编写一个函数,输入n为偶数时,调用函数求1/2+1/4+...+1/n, 当输入n为奇数时,调用函数1/1+1/3+...+1/n(利用指针函数)*/double* calculate(int n, int i){ double* p = (double *)malloc.原创 2020-05-30 15:55:09 · 1543 阅读 · 0 评论 -
判断101-200之间有多少个素数,并输出所有素数。
//判断101-200之间有多少个素数,并输出所有素数。 79个#include <stdio.h>#include <math.h>int main01(){ int count = 0; int prime[200]; int x = 0; for (int i = 101; i <= 200; i++) { for (int j = 2; j <= sqrt(i); j++) { if (i % j == 0) ..原创 2020-05-30 15:53:43 · 408 阅读 · 0 评论