摘要: 用希尔排序法对一组数据由小到大进行排序,数据分别为 69、56、12、136、3、55、46、 99、88、25。 实现过程: (1)自定义函数 shsort(),实现希尔排序。 (2) main() 函数作为程序的入口函数。程序代码如下: 1 #include <stdio.h> 2 int sh 阅读全文
posted @ 2020-08-13 22:45 C语言自学网 阅读(664) 评论(0) 推荐(0) 编辑
摘要: 如果一个渔夫从 2011 年 1 月 1 日开始每三天打一次渔,两天晒一次网,编程实现当输入 2011 1 月 1 日以后的任意一天,输出该渔夫是在打渔还是在晒网。 实现过程: (1) 自定义函数 leap(),用来判断输入的年份是否是闰年。 (2) 自定义函数 number(),用来计算输入日期距 阅读全文
posted @ 2020-08-13 22:43 C语言自学网 阅读(517) 评论(0) 推荐(0) 编辑
摘要: 中国古代数学家张丘建在他的《算经》中提出了一个著名的“百钱买百鸡问题”,鸡翁一,值钱五,鸡母一,值钱三,鸡雏三,值钱一,百钱买百鸡,问翁、母、雏各几何? 实现过程: (1) 使用 for 语句对 3 种鸡的数嫌在事先确定好的范围内进行穷举并判断,对满足条件的 3 种鸡的数量按指定格式输出,否则进行下 阅读全文
posted @ 2020-08-13 22:25 C语言自学网 阅读(1503) 评论(0) 推荐(0) 编辑
摘要: 猴子吃桃问题:猴子第一天摘下若干个桃子,当即吃了一半,还不过瘾,又多吃了一个。第二天早上又将第一天剩下的桃子吃掉一半,有多吃了一个。以后每天早上都吃了前一天剩下的一半零一个。到第 10 天早上想再吃时,发现只剩下一个桃子了。编写程序求猴子第一天摘了多少个桃子。 实现过程: (1) 定义 day、x1 阅读全文
posted @ 2020-08-13 21:55 C语言自学网 阅读(702) 评论(0) 推荐(0) 编辑
摘要: 任意输入 3 个整数,编程实现对这 3 个整数由小到大进行排序。 实现过程: (1)定义数据类型,本实例中 a、b、c、t 均为基本整型。 (2) 使用输入函数获得任意 3 个值赋给 a、b、c。 (3) 使用 if 语句进行条件判断,如果 a 大于 b,则借助于中间变量 t 互换 a 与 b 值, 阅读全文
posted @ 2020-08-13 21:51 C语言自学网 阅读(8124) 评论(0) 推荐(0) 编辑
摘要: 题目:有五个学生,每个学生有3门课的成绩,从键盘输入以上数据(包括学生号,姓名,三门课成绩),计算出平均成绩,况原有的数据和计算出的平均分数存放在磁盘文件"stud"中。 程序分析:无。 程序源代码: 1 #include<stdio.h> 2 #include<stdlib.h> 3 typede 阅读全文
posted @ 2020-08-13 21:43 C语言自学网 阅读(418) 评论(0) 推荐(0) 编辑
摘要: 题目:有两个磁盘文件A和B,各存放一行字母,要求把这两个文件中的信息合并(按字母顺序排列),输出到一个新文件C中。 程序分析:你需要先创建 A.txt 与 B.txt。 A.txt文件内容: 123 B.txt文件内容: 456 程序源代码: 1 #include<stdio.h> 2 #inclu 阅读全文
posted @ 2020-08-13 21:41 C语言自学网 阅读(209) 评论(0) 推荐(0) 编辑
摘要: 题目:从键盘输入一个字符串,将小写字母全部转换成大写字母,然后输出到一个磁盘文件"test"中保存。 输入的字符串以!结束。 程序分析:无。 程序源代码: 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 5 int ma 阅读全文
posted @ 2020-08-13 21:26 C语言自学网 阅读(212) 评论(0) 推荐(0) 编辑
摘要: 题目:从键盘输入一些字符,逐个把它们送到磁盘上去,直到输入一个#为止。 程序分析:无。 实例: 1 #include<stdio.h> 2 #include<stdlib.h> 3 int main() 4 { 5 FILE*fp=NULL; 6 char filename[25]; 7 char 阅读全文
posted @ 2020-08-13 21:23 C语言自学网 阅读(158) 评论(0) 推荐(0) 编辑
摘要: 题目:计算字符串中子串出现的次数 。 程序分析:无。 实例: 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 int main() 5 { 6 int i,j,k,TLen,PLen,count=0; 7 char T[ 阅读全文
posted @ 2020-08-13 21:21 C语言自学网 阅读(214) 评论(0) 推荐(0) 编辑
摘要: 题目:简单的结构体应用实例。 程序分析:无。 程序源代码: 1 #include <stdio.h> 2 3 struct programming 4 { 5 float constant; 6 char *pointer; 7 }; 8 9 int main() 10 { 11 struct pr 阅读全文
posted @ 2020-08-13 21:19 C语言自学网 阅读(299) 评论(0) 推荐(0) 编辑
摘要: 题目:猜谜游戏。 程序分析:无。 实例: 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <time.h> 4 5 void caizi(void) 6 { 7 int n; 8 char begin; 9 int count = 1; 1 阅读全文
posted @ 2020-08-13 21:15 C语言自学网 阅读(245) 评论(0) 推荐(0) 编辑
摘要: 题目:时间函数举例2 程序分析:无。 程序源代码: 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <time.h> 4 5 int main() 6 { 7 long i=10000000L; 8 clock_t start,finish 阅读全文
posted @ 2020-08-13 21:08 C语言自学网 阅读(120) 评论(0) 推荐(0) 编辑
摘要: 题目:时间函数举例2 程序分析:无。 程序源代码: 1 #include <stdio.h> 2 #include <time.h> 3 4 int main() 5 { 6 time_t start,end; 7 int i; 8 start=time(NULL); 9 for(i=0;i<300 阅读全文
posted @ 2020-08-13 21:07 C语言自学网 阅读(164) 评论(0) 推荐(0) 编辑
摘要: 题目:时间函数举例1 程序分析:无。 程序源代码: 1 #include <stdio.h> 2 #include <time.h> 3 4 int main () 5 { 6 time_t rawtime; 7 struct tm * timeinfo; 8 9 time ( &rawtime ) 阅读全文
posted @ 2020-08-13 21:05 C语言自学网 阅读(142) 评论(0) 推荐(0) 编辑
摘要: 题目:专升本一题,读结果。 程序分析:无。 程序源代码: 1 #include<stdio.h> 2 #include<stdlib.h> 3 4 #define M 5 5 int main() 6 { 7 int a[M]={1,2,3,4,5}; 8 int i,j,t; 9 i=0;j=M- 阅读全文
posted @ 2020-08-13 21:00 C语言自学网 阅读(122) 评论(0) 推荐(0) 编辑
摘要: 题目:某个公司采用公用电话传递数据,数据是四位的整数,在传递过程中是加密的,加密规则如下: 每位数字都加上5,然后用和除以10的余数代替该数字,再将第一位和第四位交换,第二位和第三位交换。 程序分析:无。 程序源代码: 1 #include <stdio.h> 2 3 int main() 4 { 阅读全文
posted @ 2020-08-13 20:59 C语言自学网 阅读(232) 评论(0) 推荐(1) 编辑
摘要: 题目:读取7个数(1—50)的整数值,每读取一个值,程序打印出该值个数的 *。 程序分析:无。 实例: 1 #include<stdio.h> 2 #include<stdlib.h> 3 int main() 4 { 5 int n,i,j; 6 printf("请输入数字:\n");i--; 7 阅读全文
posted @ 2020-08-13 20:57 C语言自学网 阅读(147) 评论(0) 推荐(0) 编辑
摘要: 题目:回答结果(结构体变量传递)。 程序分析:无。 实例: 1 #include<stdio.h> 2 3 struct student 4 { 5 int x; 6 char c; 7 } a; 8 9 int main() 10 { 11 a.x=3; 12 a.c='a'; 13 f(a); 阅读全文
posted @ 2020-08-13 20:56 C语言自学网 阅读(123) 评论(0) 推荐(0) 编辑
摘要: 题目:两个字符串连接程序 。 程序分析:无。 程序源代码: 1 #include <stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 5 char* strconnect(char *str1,char *str2); 6 7 int main 阅读全文
posted @ 2020-08-13 20:54 C语言自学网 阅读(143) 评论(0) 推荐(0) 编辑