随笔分类 - c语言例子
摘要:所谓排序、就是根据排序码的递增或者递减序列把数据元素依次排列起来,使一组任意排列的元素变为一组按其排序码线性有序的元素。 八大排序是《数据结构》这门大学计算机必修课中非常基础但是特别重要的知识点,在这里小编为大家盘点了八大排序。 常见的八大排序,他们之间关系如下: 下面针对不同排序进行一一讲解。 一
阅读全文
摘要:#include <stdio.h> int ab[10] ={99,1,3,8,11,34,104,87,33,41}; void insea(int a[],int n) { int i,j,x; for(i=0;i<n;i++){ if(a[i]<a[i-1]) { j=i-1; x=a[i]
阅读全文
摘要:#include <stdio.h> void fun(int *a,int *b) { int *k; k=a;a=b;b=k; } void fun1(int *a,int *b) { int k; k=*a;*a=*b;*b=k; } main() { int a=3,b=6,*x=&a,*y
阅读全文
摘要:#include <stdio.h> //a数组首地址a[0],对应第1个元素,加4,对应第5个元素 main() { int a[]={45,66,78,95,68,96,99},*b=a; printf("%d",*(a+4)); getchar(); }
阅读全文
摘要:#include <stdio.h> //逗号表达式先计算p=p+2,指向3 //*p++:*与++优先级相同,右结合性,(*)p++, //输出时先用后加,所以表达式值为3 (*p=4) // p=p+2=6 //*++p:优先级相同,右结合,*(++p),先加后用,逗号表达式值为7 main()
阅读全文
摘要:#include <stdio.h> //指针变量的值变化,则对应新的变量,原变量的值不变 main() { int m=1,n=2; int *p=&m,*q=&n,*r; r=p;p=q;q=r; printf("%d,%d,%d,%d",m,n,*p,*q); getchar(); }
阅读全文
摘要:#include <stdio.h> //一维数组 二维数组的指针 main() { int a[2][3]={{1,2,3},{4,5,6}}; int b[]={10,20,30,40,50,60}; int *p,*p1,i; p1=b;//一维数组指针 p=a[0];//二维数组指针 //p
阅读全文
摘要:#include <stdio.h> void swap(int *p1,int *p2) { int tmp=*p1; *p1=*p2; *p2=tmp; } void swap1(int *p1,int *p2){ *p1=*p1+*p2; *p2=*p1-*p2; *p1=*p1-*p2;}
阅读全文
摘要:auto:编译器在默认的缺省情况下,所有变量都是auto 的 register:register 变量必须是能被CPU 寄存器所接受的类型。意味着register 变量必须是一个单个的值,并且其长度应小于或等于整型的长度。而且register 变量可能不存放在内存中,所以不能用取址运算符“&”来获取
阅读全文
摘要:因为指针变量所对应的是地址,而整数是存放在某个地址上的内容。二者不一样
阅读全文
摘要:#include <stdio.h> main() { struct student{ char no[7]; char name[8]; int score; }; struct student st1,st2; //printf("%d\n",&student); printf("%d %d %
阅读全文
摘要:字符标志符:%cA 键盘输入:scanf("%c",&a);B 直接赋值:a='c'; 字符串(由多个字符型数据组成的一串字符)标志:%s为字符串赋值方法:A 字符串初始化:char ab[10]="asdfsdf"B 利用循环为字符数组逐个赋值: for(a=1;a<=10;a++) ab[a]=
阅读全文
摘要:#include <stdio.h> main() { int sum=0,a,b,c; for(a=1;a<=100;a++) { if(a==1) c=1; else c=0; for(b=2;b<a;b++) { if(a%b==0) { c=1; break; } } if(c==1) {
阅读全文
摘要:#include <stdio.h> main() { struct stu { int a; int b; }; struct stu ab; printf("%d",ab.a); getchar(); } int abb(struct stu ma) { } 编译时提示: 修改如下: #incl
阅读全文
摘要:#include <stdio.h> main() { int a,c=1; double sum=0,b=1.0,d,e,f; for(a=1;a<=20;a++) { d=b/(b+1); sum=sum+d; b=b+1; printf("%lf,%lf\n",b,d); } printf("
阅读全文
摘要:#include <stdio.h> main() { int x,y,z; x=0;y=z=-1; x+=-z y;//只有赋值运算符 条件运算符 求字节运算符右结合,其他都为左结合。相当于x+=-(z--)-y; //自减优先级最高先计算z--,x+=-(-1)-y //x+=1-y=1-(-1
阅读全文
摘要:#include <stdio.h> main() { struct student{ char no[8]; char name[8]; int ps; int sx; int qm; float zp; }; struct student ab[10]={ { "2020001","张三1",8
阅读全文
摘要:#include <stdio.h> struct student{ char name[12]; char number[9]; int score; }; struct student st[3]={{"zhang liang","19040301",87},{"li hong","180403
阅读全文
摘要:#include <stdio.h> struct student{ char name[12]; char number[9]; int score; }; struct student st[3]={{"zhang liang","19040301",87},{"li hong","180403
阅读全文
摘要:#include <stdio.h> static int day_tab[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}}; struct date { int year
阅读全文

浙公网安备 33010602011771号