![](https://img-blog.csdnimg.cn/efd3bc0bbb194c0baa2c9bbe2b46b2da.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
C语言笔记
C语言学习笔记
*Min*
这个作者很懒,什么都没留下…
展开
-
【C语言】数据结构与算法第一章//求素数、阶乘、等差数列、一元二次方程
#include<stdio.h>#include<math.h> /*判断是否为素数*/int main() { int n; scanf("%d",&n); int determine(int ); if(!determine(n)) printf("%d不是素数",n); else printf("%d是素数",n); return 0;}int determine(int n){ int i; for(i=2;i<=sqr...原创 2022-01-17 19:30:55 · 587 阅读 · 0 评论 -
【C语言】文件 //相关综合应用 单个字符的转换和存储、fscanf与fprintf、优化算法、结构体应用中的scanf与fprintf的区分
小写字母转成大写,并保存到文本文件中#include<stdio.h>int main(){ FILE *fp;char ch; if((fp=fopen("text.txt","w"))==NULL) { printf("cannot open!"); } while((ch=getchar())!='0') { if(ch>='A'&&ch<='Z') fprintf(fp,"%c",ch); if(ch>='a'&a.原创 2022-01-16 20:46:09 · 238 阅读 · 0 评论 -
【C语言】练习fread和fwrite//并用链表存储高分学生信息
fwrite是二进制方式写入,写入后的文件不是文本格式,不能用文本编辑器打开,只有纯文本文件才能用记事本打开,这是二进制文件 。#include<stdio.h> #include<stdlib.h>#define N 10/*求最高分学生*/ typedef struct student{ int num; char name[10]; char sex; float score; struct student *next;}STU;int ma.原创 2022-01-15 20:27:26 · 850 阅读 · 0 评论 -
【C语言】背单词程序//调用外部文件练习
注意!!Win10记事本默认按UTF编码,但fscanf只能简单读取,所以需要转换格式#include<stdio.h>#include<stdlib.h>#include<Windows.h>#include<string.h>#define N 3int cmpcns(const char *p,const char *b)// 判断输入中文是否正确 (母串子串) { int k; if(strlen(b)<(strle...原创 2022-01-13 17:19:57 · 463 阅读 · 0 评论 -
C语言【练习结构体指针,指针数组】
找出最低分数的同学,储存到h指向的结构体数组#include<stdio.h>#include<math.h>#define N 10#define eps 1e-4struct stu{ double num; float score;};int main() { struct stu s[N],low[N],*Q=s,*h=low; int i;float min=100.0; for(i=0;i<N;i++) { scanf("%.原创 2021-12-30 13:06:06 · 734 阅读 · 3 评论 -
C语言【结构体中运用指针数组,函数练习】
#include<stdio.h>struct student{ int num; char name[8]; char sex; int age; double grade;};int i,j;int main() { struct student *stu[10],input[10],temp; void inputdata(); inputdata(stu,input,temp); void outputdata(); outputdata(stu);.原创 2021-12-23 13:17:12 · 637 阅读 · 2 评论 -
C语言【结构体练习改进】//尝试使用const修饰结构指针,并把结构体变量定义在函数内,避免影响封装
//尝试使用const关键词,并把结构体变量定义在函数内,避免影响封装 #include<stdio.h>struct score{ int chinese; int english; int math;};struct student{ double num; char name[20]; struct score subjects; //结构体嵌套};int main() { struct student *p,person[5]; p=person; .原创 2021-12-22 17:10:59 · 805 阅读 · 0 评论 -
C语言【结构体】//结构体变量做函数参数,结构体嵌套
//结构体变量做函数参数,结构体嵌套#include<stdio.h>struct score{ int chinese; int english; int math;};struct student{ double num; char name[20]; struct score subjects; //结构体嵌套}person[5];int main() { struct student *p; p=person; int i,j; for(i=0;i.原创 2021-12-19 22:26:11 · 561 阅读 · 2 评论 -
C语言【利用指向指针的指针实现字符串排序,结构数组与结构体指针,结构体计算名字出现次数 】
利用指向指针的指针实现字符串排序#include<stdio.h>#include<string.h>int main(){ char *str[]={"C","PROGRAMMING","LANGUAGE"},**p,*temp; int n=sizeof(str)/sizeof(str[0]),i,j,k;//计算长度 p=str; for(i=0;i<n-1;i++)//按从小到大排序,选择排序法 { k=i; for(j=i..原创 2021-12-19 11:53:42 · 780 阅读 · 0 评论 -
C语言【利用行指针实现4*4二维数组转置】
如果用行指针,最后输出时可以用*(*p+i)//相当于*(*(p+0)+i)如果用普通指针,最后输出可以用*(p+i)//行指针 取两次地址,所以定位的时候直接p=a;#include<stdio.h>int main(){ int a[4][4]= { {1,2,3,4}, {5,6,7,8}, {9,10,11,12}, {13,14,15,16} }; int (*p)[4],temp,i,j; p=a; for(i=0;i<4;..原创 2021-12-18 22:41:32 · 3309 阅读 · 2 评论 -
C语言【关于函数返回地址的二三事】
关于指针数组关于字符型数组关于字符型指针#include<stdio.h>#include<stdlib.h> int main(){ int i; char *Dayname(); char *str=Dayname(); printf("%s\n",str); return 0;} /*char *Dayname(int n){ char *name[]={"illegalday","mon","tue","wed","th...原创 2021-12-18 17:44:31 · 2250 阅读 · 0 评论 -
C语言//利用指针数组做了一个背单词小程序,有绿色红色提醒,提高了汉译的容错率,增加了英汉互听和算分的功能
容错率//满足输入子串在母串中出现且不低于母串字符数的一半#include<stdio.h>#include<Windows.h>#include<string.h> int cmpcns(const char *p,const char *b)// 判断输入中文是否正确 (母串子串) { int k; if(strlen(b)<(strlen(p)/2)) return 0;//输入字符不低于母串个数一半 for(k=0;(k<strle原创 2021-12-16 21:46:56 · 627 阅读 · 1 评论 -
C语言 利用指针数组做了一个背单词小程序//通过改变代码录入英文和汉字的顺序可以实现中英互背
利用指针数组做了一个背单词小程序,有绿色红色提醒//通过改变代码录入英文和汉字的顺序可以实现中英互背原创 2021-12-15 23:21:52 · 510 阅读 · 0 评论 -
C语言[练习函数中指针传递,循环条件嵌套]//把关键字打在后面应该就不会被同学发现作业答案吧//自定义strcmp函数,判断回文
//把关键字打在后面应该就不会被同学发现作业答案吧比较输入字符串的大小判断回文数原创 2021-12-13 23:26:31 · 571 阅读 · 0 评论 -
C语言[指针实现二维数组的转置]
利用指针实现二维数组的转置原创 2021-12-11 23:26:27 · 2084 阅读 · 0 评论 -
C语言[指针实现数组的逆序输出,函数中指针传递,指针地址概念,困难版的删重]
利用指针实现输入数组的逆序输出相同作用,练习一下函数中指针的传递%p打地址//深入理解指针地址概念%u打地址将输入字符串字符按从小到大排列并删去重复//昨天的简易版同样作用但不想新建数组//练习while和switch...原创 2021-12-10 23:59:30 · 777 阅读 · 0 评论 -
C语言[找3位连续数,矩阵计算周围一圈数字合,指针连接字符串,计算长度,输入字符排列并删同,指针初始规范]
在输入数中找3位连续数在4*4矩阵里计算周围一圈的数字合指针连接两个字符串用指针计算字符串长度将输入字符串字符按从小到大排序并删去重复字符指针定义和初始化的规范原创 2021-12-09 22:57:49 · 554 阅读 · 0 评论 -
C语言[寻找素数,寻找特殊条件数,查找子串出现次数,顺序插入新数]
寻找1000到3000之间的素数并以每行5个输出找出100到500间符合条件的数//个十百相乘等于42个十百相加等于12找出子串在母串中出现的次数//母串str[]=“abcdeabcdeabcdefg”;子串substr[]=“abc”;已知10位同学的成绩,将他们的成绩排序后再插入另一同学的成绩//要求从小到大顺序...原创 2021-12-08 18:28:18 · 553 阅读 · 0 评论