C语言学习(小甲鱼)

  • 第二章:数据类型,运算符和表达式
    • 2.1:数据类型,运算符和表达式1
    • 2.2:数据类型,运算符和表达式2
    • 2.3:数据类型,运算符和表达式3
    • 2.4: 数据类型,运算符和表达式4
    • 2.5: 数据类型,运算符和表达式5
  • 第三章:顺序程序设计
    • 3.1:顺序程序设计01
    • 3.2: 顺序程序设计02
  • 第四章:
    • 4.1:分支结构程序01
    • 4.2:分支结构程序02
    • 4.3:分支结构程序03
    • 4.4:分支结构程序04
  • 第五章:循环控制结构程序
    • 5.1:循环控制结构01
    • 5.2:循环控制结构02
    • 5.3:循环控制结构03
    • 5.4:循环控制结构04
  • 第六章:数组
    • 6.1:数组01
    • 6.2:数组02
    • 6.3:数组03
  • 第七章:函数
    • 7.1:函数01
    • 7.2:函数02
    • 7.3:函数03
    • 7.4:函数04
    • 7.5:函数05
    • 7.6:函数06
  • 第八章:指针
    • 8.1:指针01
    • 8.2:指针02
    • 8.3:指针03
    • 8.4:指针04

第二章:数据类型,运算符和表达式

2.1:数据类型,运算符和表达式1






例3.1:

/*
时间:2022.10.01 14:51
功能:
目的:符号常量的使用
*/
#include <stdio.h>#define PRICE 30;void  main()
{int num,total;num =10 ;total=num*PRICE;printf("total=%d\n",total);}
/*
在VC6++上的运行结果为:
total=300
Press any key to continue*/




2.2:数据类型,运算符和表达式2

/*
时间:2022.10.01 15:12
功能:
目的:测试此编译器int 占几个字节
*/
#include <stdio.h>void  main()
{printf("%d\n",sizeof(int));}
/*
在VC6++上的运行结果为:
4
Press any key to continue*/
/*
时间:2022.10.01 15:15
功能:
目的:测试此编译器short占几个字节
*/
#include <stdio.h>void  main()
{printf("%d\n",sizeof(short));}
/*
在VC6++上的运行结果为:
2
Press any key to continue*/
/*
时间:2022.10.01 15:15
功能:
目的:测试此编译器float占几个字节
*/
#include <stdio.h>void  main()
{printf("%d\n",sizeof(float));}
/*
在VC6++上的运行结果为:
4
Press any key to continue*/


/*
时间:2022.10.01 15:18
功能:
目的:例3.2 整型变量的定义与使用
*/#include <stdio.h>void main()
{int a,b,c,d;unsigned u;a=12;b=-24;u=10;c=a+u;d=b+u;printf("a+u=%d,b+u=%d\n",c,d);
}/*
在VC6++上的运行结果为:
a+u=22,b+u=-14
Press any key to continue*/
/*
时间:2022.10.01 15:27
功能:
目的:例3.3 整型数据的溢出
*/#include <stdio.h>void main()
{short int a,b;a=32767;b=a+1;printf("%d,%d\n",a,b);
}/*
在VC6++上的运行结果为:
32767,-32768
Press any key to continue*/

/*
时间:2022.10.01 15:30
功能:
目的:例3.4
*/#include <stdio.h>void main()
{long x,y;int a,b,c,d;x=5;y=6;a=7;b=8;c=x+a;d=y+b;printf("c=x+a=%d,d=y+b=%d\n",c,d);
}/*
在VC6++上的运行结果为:
c=x+a=12,d=y+b=14
Press any key to continue
*/





2.3:数据类型,运算符和表达式3

/*
时间:2022.10.01 15:38
功能:
目的:例3.6 实型数据的舍入误差
*/#include <stdio.h>void main()
{float a,b;a=123456.789e5;b=a+20;printf("%f\n",a);printf("%f\n",b);
}/*
在VC6++上的运行结果为:
12345678848.000000
12345678848.000000
Press any key to continue
*/


/*
时间:2022.10.01 15:47
功能:
目的:测试1.0/3*3等于多少
*/#include <stdio.h>void main()
{printf("%f\n",1.0/3*3);
}/*
在VC6++上的运行结果为:
1.000000
Press any key to continue*/
/*
时间:2022.10.01 15:47
功能:
目的:测试3/2等于多少
*/#include <stdio.h>void main()
{printf("%f\n",3/2);
}/*
在VC6++上的运行结果为:
0.000000
Press any key to continue*/
/*
时间:2022.10.01 15:47
功能:
目的:测试1/3*3等于多少
*/#include <stdio.h>void main()
{printf("%f\n",1/3*3);
}/*
在VC6++上的运行结果为:
0.000000
Press any key to continue*/



/*
时间:2022.10.01 15:53
功能:
目的:例3.8 转义字符的使用
*/#include <stdio.h>void main()
{int a,b,c;a=5;b=6;c=7;printf("ab c\tde\rf\n");printf("hijk\tL\bM\n");
}/*
在VC6++上的运行结果为:
fb c    de
hijk    M
Press any key to continue*/



```c
/*
时间:2022.10.01 16:01
功能:
目的:例3.9 向字符变量赋以整数
*/#include <stdio.h>void main()
{char a,b;a=120;b=121;printf("%c,%c\n",a,b);printf("%d,%d\n",a,b);
}/*
在VC6++上的运行结果为:
x,y
120,121
Press any key to continue*/

/*
时间:2022.10.01 16:01
功能:
目的:例3.10 小写字母换成大写字母
*/#include <stdio.h>void main()
{char a,b;a='a';b='b';a=a-32;b=b-32;printf("%c,%c\n%d,%d\n",a,b,a,b);
}/*
在VC6++上的运行结果为:
A,B
65,66
Press any key to continue*/


2.4: 数据类型,运算符和表达式4



/*
时间:2022.10.01 17:10
功能:
目的:例3.1.2 各类数值型数据之间的混合运算
*/#include <stdio.h>void main()
{float PI=3.14159;int s,r=5;s=r*r*PI;printf("s=%d\n",s);
}/*
在VC6++上的运行结果为:
s=78
Press any key to continue*/


/*
时间:2022.10.01 17:16
功能:
目的:例3.1.3 强制转换
*/#include <stdio.h>void main()
{float f=5.75;printf("(int)f=%d,f=%f\n",(int)f,f);
}/*
在VC6++上的运行结果为:
(int)f=5,f=5.750000
Press any key to continue*/


/*
时间:2022.10.01 17:25
目的:例3.14
*/#include <stdio.h>void main()
{printf("\n\n%d,%d\n",20/7,-20/7);printf("%f,%f\n",20.0/7,-20.0/7);
}/*
在VC6++上的运行结果为:
2,-2
2.857143,-2.857143
Press any key to continue*/
/*
时间:2022.10.01 17:30
目的:例3.15
*/#include <stdio.h>void main()
{printf("%d\n",100%3);
}/*
在VC6++上的运行结果为:
1
Press any key to continue*/
/*
时间:2022.10.01 17:30
目的:测试%-----取余
*/#include <stdio.h>void main()
{printf("7除以2=%d------%d\n",7/2,7%2);
}/*
在VC6++上的运行结果为:
7除以2=3------1
Press any key to continue*/

2.5: 数据类型,运算符和表达式5







/*
时间:2022.10.01 19:06
目的:例3.18 类型转换
*/#include <stdio.h>void main()
{int a,b=322;float x,y=8.88;char c1='k',c2;a=y;x=b;a=c1;c2=b;printf("%d,%f,%d,%c\n",a,x,a,c2);
}/*
在VC6++上的运行结果为:
107,322.000000,107,B
Press any key to continue*/

/*
时间:2022.10.01 19:14
目的:例3.19 逗号运算符合逗号表达式
*/#include <stdio.h>void main()
{int a=2,b=4,c=6,x,y;y=((x=a+b),(b+c));printf("y=%d,x=%d\n",y,x);
}/*
在VC6++上的运行结果为:
y=10,x=6
Press any key to continue
*/

第三章:顺序程序设计

3.1:顺序程序设计01











/*
时间:2022.10.01 19:29
目的:例4.1 输出单个字符
*/#include <stdio.h>void main()
{char a='B',b='o',c='k';putchar(a);putchar(b);putchar(b);putchar(c);putchar('\t');putchar(a);putchar(b);putchar('\n');putchar(b);putchar(c);
}/*
在VC6++上的运行结果为:
Book    Bo
okPress any key to continue
*/


/*
时间:2022.10.01 19:54
目的:例4.2 输入单个字符
*/
#include <stdio.h>void main()
{char c;printf("input a character\n");c=getchar();putchar(c);}
/*
在VC6++上的运行结果为
input a character
h
hPress any key to continue*/



/*
时间:2022.10.01 20:00
目的:例4.2 输入单个字符
*/
#include <stdio.h>void main()
{int a=88,b=89;printf("%d %d\n",a,b);printf("%d,%d\n",a,b);printf("%c,%c\n",a,b);printf("a=%d,b=%d\n",a,b);}
/*
在VC6++上的运行结果为
88 89
88,89
X,Y
a=88,b=89
Press any key to continue*/





3.2: 顺序程序设计02



/*
时间:2022.10.01 20:14
目的:例4.7 格式输入
*/
#include <stdio.h>void main()
{int a,b,c;printf("input a,b,c\n");scanf("%d %d %d",&a,&b,&c);printf("a=%d,b=%d,c=%d\n",a,b,c);}
/*
在VC6++上的运行结果为
input a,b,c
14
12
13
a=14,b=12,c=13
Press any key to continue*/





/*
时间:2022.10.01 20:29
目的:例4.7 格式输入
*/
#include <stdio.h>void main()
{char a,b;printf("input character a,b\n");scanf("%c%c",&a,&b);printf("%c%c\n",a,b);}
/*
在VC6++上的运行结果为
input character a,b
3
3Press any key to continue*/





/*
时间:2022.10.01 20:42
目的:例4.12 输入三个小写字母,输出起ASCII码和对应的大写字母
*/
#include <stdio.h>void main()
{char a,b,c;printf("input character a,b,c\n");scanf("%c%c%c",&a,&b,&c);printf("%d,%d,%d,%c,%c,%c\n",a,b,c,a-32,b-32,c-32);}
/*
在VC6++上的运行结果为
input character a,b,c
abc
97,98,99,A,B,C
Press any key to continue*/


/*
时间:2022.10.01 20:43
目的:例4.13 输出各种数据类型的字节长度
*/
#include <stdio.h>void main()
{int a;long b;float f;double d;char c;printf("\n int:%d\n long:%d\n float:%d\n double:%d\b char:%d\n",sizeof(a),sizeof(b),sizeof(c),sizeof(d),sizeof(c));}
/*
在VC6++上的运行结果为int:4long:4float:1double: char:1
Press any key to continue
*/

第四章:

4.1:分支结构程序01



/*
时间:2022.10.01 21:46
目的:
*/
#include <stdio.h>void main()
{char c='k';int i=1,j=2,k=3;float x=3e+5,y=0.85;printf("%d,%d\n",'a'+5<c,-i-2*j>=k+1);printf("%d,%d\n",1<j<5,x-5.25<=x+y);printf("%d,%d\n",i+j+k==-2*j,k==j==i+5);
}/*
在VC6++运行的结果为:
1,0
1,1
0,0
Press any key to continue
*/




/*
时间:2022.10.01 21:46
目的:
*/
#include <stdio.h>void main()
{char c='k';int i=1,j=2,k=3;float x=3e+5,y=0.85;printf("%d,%d\n",'a'+5<c,-i-2*j>=k+1);printf("%d,%d\n",1<j<5,x-5.25<=x+y);printf("%d,%d\n",i+j+k==-2*j,k==j==i+5);
}/*
在VC6++运行的结果为:
1,0
1,1
0,0
Press any key to continue
*/

4.2:分支结构程序02


/*
时间:2022.10.01 22:12
目的:例5.3 if的第一种形式
*/
#include <stdio.h>void main()
{int a,b,max;printf("\n input two numbers: ");scanf("%d%d",&a,&b);max=a;if(max<b)max=b;printf("max=%d\n",max);
}/*
在VC6++运行的结果为:input two numbers: 3 5
max=5
Press any key to continue
*/


/*
时间:2022.10.01 22:22
目的:例5.3 if的第二种形式
*/
#include <stdio.h>void main()
{int a,b,max;printf("\n input two numbers: ");scanf("%d%d",&a,&b);if(a>b){printf("max=%d\n",a);}else{printf("max=%d\n",b);}}/*
在VC6++运行的结果为:input two numbers: 2 3
max=3
Press any key to continue*/


/*
时间:2022.10.01 22:27
目的:例5.5 if的第三种形式
*/
#include <stdio.h>void main()
{char c;printf("input a character: ");c=getchar();if(c<32){printf("This is a control character\n");}else if(c>='0'&&c<='9'){printf("This is a digit\n");}else if(c>='A'&&c<='Z'){printf("This is a small letter\n");}else{printf("This an other character\n");}
}

4.3:分支结构程序03




#include <stdio.h>void main()
{int score;scanf("%d\n",&score);if(score<60){printf("The score is E\n");}else if((score>60||score==60) && score<70){printf("The score is D\n");}else if((score>70||score==70)&&score<80){printf("The score is C\n");}else if((score>80||score==80) && score<90){printf("The score is B\n");}else {printf("The score is A");}
}

/*
时间:2022.10.02 13:44
目的:从大到小三个数排序
*/#include <stdio.h>void main()
{int a,b ,c,temp;printf("please input three numbers:");scanf("%d %d %d",&a,&b,&c);if(a>b){temp=a;a=b;b=temp;}if(a>c){temp=a;a=c;c=temp;}if(b>c){temp=b;b=c;c=temp;}printf("%d%d%d\n",a,b,c);
}/*
在VC6++上运行的结果是:please input three numbers:45 62 85
456285
Press any key to continue
*/

4.4:分支结构程序04




/*
时间:2022.10.02 13:49
目的:if语句的嵌套
*/#include <stdio.h>void main()
{int a,b;printf("please input A,B:");scanf("%d %d",&a,&b);if(a!=b)if(a>b) printf("A>B\n");else printf("A<B\n");else printf("A=B\n");
}/*
在VC6++上运行的结果是:please input A,B:3 6
A<B
Press any key to continue
*/



/*
时间:2022.10.02 14:00
目的:条件运算符
*/#include <stdio.h>void main()
{int a,b,max;printf("\n input two numbers: ");scanf("%d %d",&a,&b);printf("max=%d\n",a>b?a:b);
}/*
在VC6++上运行的结果是:input two numbers: 6 8
max=8
Press any key to continue*/



/*
时间:2022.10.02 14:08
目的:条件运算符
*/#include <stdio.h>void main()
{int a;printf("input integer numbers:   ");scanf("%d",&a);switch(a){case 1:printf("Modany\n"); break;case 2:printf("Tuesday\n"); break;case 3:printf("Wednesday\n"); break;case 4:printf("Thursday\n"); break;case 5:printf("Friday\n"); break;case 6:printf("Saturday\n"); break;case 7:printf("Sunday\n"); break;default:printf("error\n");}
}/*
在VC6++上运行的结果是:input integer numbers:   6
Saturday
Press any key to continue*/
/*
时间:2022.10.02 14:08
目的:条件运算符
*/#include <stdio.h>void main()
{int a;printf("input integer numbers:   ");scanf("%d",&a);switch(a){case 1:printf("Modany\n"); case 2:printf("Tuesday\n"); case 3:printf("Wednesday\n"); case 4:printf("Thursday\n"); case 5:printf("Friday\n");case 6:printf("Saturday\n"); case 7:printf("Sunday\n"); default:printf("error\n");}
}/*
在VC6++上运行的结果是:input integer numbers:   1
Modany
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday
error
Press any key to continue*/

第五章:循环控制结构程序

5.1:循环控制结构01



/*
时间:2022.10.02 14:29
目的:条件运算符
*/#include <stdio.h>void main()
{int i,sum=0;i=1;
loop: if(i<=100){sum=sum+i;i++;goto loop;}printf("%d\n",sum);
}/*
在VC6++上运行的结果是:5050
Press any key to continue*/


/*
时间:2022.10.02 14:38
目的:用while求n个和
*/#include <stdio.h>void main()
{int i,sum=0;i=1;while(i<=100){sum=sum+i;i++;}printf("%d\n",sum);
}/*
在VC6++上运行的结果是:5050
Press any key to continue*/


/*
时间:2022.10.02 14:46
目的:例6.3 统计从键盘输入一行字符的个数
*/#include <stdio.h>void main()
{int n=0;printf("input a sting:\n");while(getchar()!='\n'){n++;}printf("%d",n);
}/*
在VC6++上运行的结果是:input a sting:
gbiubhihi
9Press any key to continue*/

5.2:循环控制结构02



/*
时间:2022.10.02 15:13
目的:用do while 求和
*/#include <stdio.h>void main()
{int i,sum=0;i=1;do{sum=sum+i;i++;}while(i<=100);printf("%d\n",sum);}/*
在VC6++上运行的结果是:5050
Press any key to continue*/

5.3:循环控制结构03


/*
时间:2022.10.02 15:29
目的:用for求和
*/#include <stdio.h>void main()
{int i,sum=0;for(i=1;i<=100;i++){sum=sum+i;}printf("%d\n",sum);}/*
在VC6++上运行的结果是:5050
Press any key to continue*/





/*
时间:2022.10.02 15:37
目的:循环的嵌套
*/#include <stdio.h>void main()
{int i,j,k;printf("i j k\n");for(i=0;i<2;i++)for(j=0;j<2;j++)for(k=0;k<2;k++)printf("%d %d %d\n",i,j,k);}/*
在VC6++上运行的结果是:
i j k
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
Press any key to continue*/

/*
时间:2022.10.02 15:50
目的:循环的嵌套
*/#include <stdio.h>void main()
{int i,j;for(i=1;i<7;i++){printf("\n");for(j=1;j<=i;j++){putchar('*');}}}/*
在VC6++上运行的结果是:
*
**
***
****
*****
******Press any key to continue
Press any key to continue*/

5.4:循环控制结构04

/*
时间:2022.10.02 16:30
目的:
*/#include <stdio.h>void main()
{int i,j,k;for(i=1;i<5;i++){for(j=1;j<5;j++){for(k=1;k<5;k++){if(i!=j&&j!=k&&i!=k){printf("%d %d %d\n ",i,j,k);}}}}}/*
在VC6++上运行的结果是:
1 2 31 2 41 3 21 3 41 4 21 4 32 1 32 1 42 3 12 3 42 4 12 4 33 1 23 1 43 2 13 2 43 4 13 4 24 1 24 1 34 2 14 2 34 3 14 3 2Press any key to continue*/

第六章:数组

6.1:数组01








6.2:数组02

/*时间:2022.10.04 9:31目的:数组的定义与输出
*/#include <stdio.h>void main()
{int i,a[10];for(i=0;i<=9;i++){a[i]=i;}for(i=9;i>=0;i--){printf("%d\n",a[i]);}
}/*
在VC6++上运行的结果为:
9
8
7
6
5
4
3
2
1
0
Press any key to continue*/
/*时间:2022.10.04 9:35目的:数组的赋初值
*/#include <stdio.h>void main()
{int i,a[10]={0,1,2,3,4,5,6,7,8,9};for(i=9;i>=0;i--){printf("%d\n",a[i]);}
}/*
在VC6++上运行的结果为:
9
8
7
6
5
4
3
2
1
0
Press any key to continue*/





/*时间:2022.10.04 9:46目的:数组的动态赋值
*/#include <stdio.h>void main()
{int i,max,a[10];printf("input 10 numbers:\n");for(i=0;i<10;i++){scanf("%d",&a[i]);}max=a[0];for(i=1;i<10;i++){if(a[i]>max){max=a[i];}printf("maxmum=%d\n",max);}
}/*
在VC6++上运行的结果为:
input 10 numbers:
0
1
2
3
4
5
6
7
8
9
maxmum=1
maxmum=2
maxmum=3
maxmum=4
maxmum=5
maxmum=6
maxmum=7
maxmum=8
maxmum=9
Press any key to continue*/

6.3:数组03

/*时间:2022.10.04 10:14目的:
*/#include <stdio.h>void main()
{int i,j,s=0,average,v[3];int a[5][3]={{80,75,92},{61,65,71},{85,63,70},{85,87,90},{76,77,85}};for(i=0;i<3;i++){for(j=0;j<5;j++){s=s+a[j][i];}v[i]=s/5;s=0;}average=(v[0]+v[1]+v[2])/3;printf("math:%d\nc languang:%d\ndFoxpro:%d\n",v[0],v[1],v[2]);printf("total:%d\n",average);
}/*
在VC6++上运行的结果为:
math:77
c languang:73
dFoxpro:81
total:77
Press any key to continue
*/

第七章:函数

7.1:函数01




/*时间:2022.10.04 10:27目的:函数的调用
*/#include <stdio.h>void main()
{void printstar();void print_message();printstar();print_message();printstar();}
void printstar()//定义函数printstar
{printf("************\n");
}
void print_message()//定义print_message
{printf("123456\n");
}/*
在VC6++上运行的结果为:
************
123456
************
Press any key to continue*/

7.2:函数02













7.3:函数03











/*时间:2022.10.04 14:12目的:函数的调用
*/#include <stdio.h>void main()
{float add(float x,float y);float a,b,c;scanf("%f,%f",&a,&b);c=add(a,b);printf("sunm is %f\n",c);
}
float add(float x,float y)
{float z;z=x+y;return z;
}
/*
在VC6++上运行的结果为:
3.55,6.35
sunm is 9.900000
Press any key to continue*/

7.4:函数04



/*时间:2022.10.04 14:47目的:函数的嵌套
*/#include <stdio.h>long square(int p);//实现平方
long factorial(int q);//实现阶乘void main()
{int i;long s=0;for(i=2;i<=3;i++){s=s+square(i);}printf("%d\n",s);
}long square(int p)
{int k;long r;long factorial();k=p*p;r=factorial(k);return r;
}long factorial(int q)
{long c=1;int i;for(i=1;i<=q;i++){c*=i;}return c;
}/*
在VC6++上运行的结果为:
362904
Press any key to continue*/


/*时间:2022.10.04 15:18目的:递归
*/#include <stdio.h>long recursion(int n);//定义函数递归void main()
{int n;long result;printf("input a integer number:\n");scanf("%d",&n);result = recursion(n);printf("%d!=%ld\n",n,result);
}long recursion(int n)
{long temp_result;if(n<0){printf("n<0,input error!\n");}else if(n==0||n==1){temp_result=1;}else{temp_result=recursion(n-1)*n;}return temp_result;
}/*
在VC6++上运行的结果为:
input a integer number:
6
6!=720
Press any key to continue*/


/*时间:2022.10.04 16:08目的:hanoi搬盘子
*/#include <stdio.h>int main()
{int hanoi(int, char, char, char);   //汉诺塔方法声明int n, counter;printf("输入层数:");scanf("%d", &n);printf("\n");counter = hanoi(n, 'A', 'B', 'C');return 0;
}int hanoi(int n, char x, char y, char z)
{int move(char, int, char); //转移方法声明if (n == 1)move(x, 1, z);else{hanoi(n - 1, x, z, y);  //递归调用,第一轮,将A柱中的N-1层通过C柱,转移到Bmove(x, n, z);   //第二轮,将A柱中的最底层转移到C柱hanoi(n - 1, y, x, z); //递归调用,第三轮,将B柱中原本的N-1层,通过A柱转移到C柱上}return 0;
}int move(char getone, int n, char putone)
{static int k = 1;printf("%2d:%3d # %c---%c\n", k, n, getone, putone);if (k++ % 3 == 0)printf("\n");return 0;
}/*
在VC6++上运行的结果为:
输入层数:61:  1 # A---B2:  2 # A---C3:  1 # B---C4:  3 # A---B5:  1 # C---A6:  2 # C---B7:  1 # A---B8:  4 # A---C9:  1 # B---C10:  2 # B---A
11:  1 # C---A
12:  3 # B---C13:  1 # A---B
14:  2 # A---C
15:  1 # B---C16:  5 # A---B
17:  1 # C---A
18:  2 # C---B19:  1 # A---B
20:  3 # C---A
21:  1 # B---C22:  2 # B---A
23:  1 # C---A
24:  4 # C---B25:  1 # A---B
26:  2 # A---C
27:  1 # B---C28:  3 # A---B
29:  1 # C---A
30:  2 # C---B31:  1 # A---B
32:  6 # A---C
33:  1 # B---C34:  2 # B---A
35:  1 # C---A
36:  3 # B---C37:  1 # A---B
38:  2 # A---C
39:  1 # B---C40:  4 # B---A
41:  1 # C---A
42:  2 # C---B43:  1 # A---B
44:  3 # C---A
45:  1 # B---C46:  2 # B---A
47:  1 # C---A
48:  5 # B---C49:  1 # A---B
50:  2 # A---C
51:  1 # B---C52:  3 # A---B
53:  1 # C---A
54:  2 # C---B55:  1 # A---B
56:  4 # A---C
57:  1 # B---C58:  2 # B---A
59:  1 # C---A
60:  3 # B---C61:  1 # A---B
62:  2 # A---C
63:  1 # B---CPress any key to continue*/




7.5:函数05













7.6:函数06





第八章:指针

8.1:指针01














/*时间:2022.10.05 15:34目的:通过指针变量访问整型变量*/
#include <stdio.h>void main()
{int a,b;int *pointer_1, *pointer_2;a=100;b=10;pointer_1=&a;pointer_2=&b;printf("%d,%d\n",a,b);printf("%d,%d\n",*pointer_1,*pointer_2);
}/*
在VC6++上运行结果为:
100,10
100,10
Press any key to continue
*/

8.2:指针02






/*时间:2022.10.05 15:47目的:输入a b两个整数,按先大后小的顺序输出a b*/
#include <stdio.h>void main()
{int *p1,*p2,*p,a,b;scanf("%d,%d",&a,&b);p1=&a;p2=&b;if(a<b){p=p1;p1=p2;p2=p;}//此后,p1指向b,p2指向aprintf("a=%d,b=%d\n",a,b);printf("max=%d,min=%d\n",*p1,*p2);
}/*
在VC6++上运行结果为:
2,3
a=2,b=3
max=3,min=2
Press any key to continue
*/
/*时间:2022.10.05 15:54目的:输入a b两个整数,按先大后小的顺序输出a b,用函数实现*/
#include <stdio.h>void swap(int *p1,int *p2);//定义交换函数void main()
{int a,b;int *pointer_1,*pointer_2;scanf("%d %d",&a,&b);pointer_1=&a;pointer_2=&b;if(a<b){swap(pointer_1,pointer_2);}printf("\n%d>%d\n",a,b);
}void swap(int *p1,int *p2)
{int temp;temp=*p1;*p1=*p2;*p2=temp;
}/*
在VC6++上运行结果为:
5 66>5
Press any key to continue*/





8.3:指针03

/*时间:2022.10.05 16:21目的:输出数组中的全部元素*/
#include <stdio.h>void main()
{int a[10];int i;for(i=0;i<10;i++){scanf("%d",&a[i]);}printf("\n");for(i=0;i<10;i++){printf("%d\n",*(a+i));}
}/*
在VC6++上运行结果为:
1 2 3 4 5 6 7 8 9 101
2
3
4
5
6
7
8
9
10
Press any key to continue*/



/*时间:2022.10.05 16:30目的:数组交换元素*/
#include <stdio.h>void reverse(int x[],int n);//形参x是数组名void main()
{int i,a[10]={3,7,9,11,0,6,7,5,4,2};printf("The original array:\n");for(i=0;i<10;i++){printf("%d",a[i]);}printf("\n");reverse(a,10);printf("The array has been inverted:\n");for(i=0;i<10;i++){printf("%d",a[i]);}
}void reverse(int x[],int n)
{int temp,i,j,m;m=(n-1)/2;for(i=0;i<=m;i++){j=n-1-i;temp=x[i];x[i]=x[j];x[j]=temp;}
}/*
在VC6++上运行结果为:
The original array:
37911067542
The array has been inverted:
24576011973Press any key to continue*/

8.4:指针04

C语言学习(小甲鱼)相关推荐

  1. Python学习小甲鱼视频做的笔记(持续更新中)

    Python BIF :Built-in functions(内建函数) Python与大多数其他计算机语言的做法稍有不同,他并不是把值存储在变量中,而更像是把名字贴在值的上边. 在使用变量之前,必须 ...

  2. Python学习小甲鱼视频003

    变量 变量名就类似于我们现实社会的名字,发一个值赋值给一个名字的时候,它会存储在内存中,称之为变量(Variable) 但是Python并没有将值存储在变量中,而更像是把名字贴在值上.或者说Pytho ...

  3. 汇编语言实验七 学习小甲鱼实验代码

    代码部分: assume cs:codesg,ds:data,es:tabledata segmentdb '1975','1976','1977','1978','1979','1980','198 ...

  4. 第五章 列表、元组和字符串[DDT书本学习 小甲鱼]【6】

    5.3.1 字符串的各种内置方法 表5-1很多暂时略掉!!!!!!!!! 选择几个常用的演示一下 casefold()方法,它的作用是将字符串的所有字符变为小写 代码 str1="DaoDa ...

  5. 第七章 字典和集合[DDT书本学习 小甲鱼]【2】

    7.1.2 字典的各种内置方法 在序列里为不存在位置赋值,会出现错误: 而在字典不存在得位置赋值,会创建.工厂函数(类型) 以前学过 str(),int(),list(),tuple()....... ...

  6. 第五章 列表、元组和字符串[DDT书本学习 小甲鱼]【2】

    5.1.7 一些常用操作符 代码 lis1=[123] lis2=[456] print(lis1>lis2) ---------------- False lis1=["abc&qu ...

  7. 第五章 列表、元组和字符串[DDT书本学习 小甲鱼]【8】

    3 Python的转义字符及含义 ------------------------------------- \'单引号 \r回车符 \"双引号 \f换页符 \a发出声 \o八进制代表的字符 ...

  8. 【Scratch】《零基础入门学习Scratch》(小甲鱼)笔记二

    〇.前情提要 充当少儿学习小甲鱼的<零基础入门学习Scratch>. 参考: [少儿编程]<零基础入门学习Scratch>(小甲鱼) https://www.bilibili. ...

  9. 【Python】办公篇-《极客Python之效率革命》(小甲鱼) 笔记一

    〇.前情提要 学习小甲鱼的使用Python读写Excel文件.这是上篇. 参考: [办公篇]<极客Python之效率革命>(小甲鱼)https://www.bilibili.com/vid ...

  10. 小甲鱼之浅谈杀与不杀

    你杀或者不杀我,我就在那里不悲不喜 借用黑客防线的名言:在攻与防的对立统一中寻求突破! 小甲鱼从现在开始就厚着脸皮跟大家来谈谈杀毒软件查杀病毒.木马的原理以及病毒.木马如何做出应对和反击的措施. 第一 ...

最新文章

  1. vue切换class_Vue点击切换Class变化,实现Active当前样式操作
  2. spingboot实现redis的发布订阅
  3. java json帮助类_java 写一个JSON解析的工具类
  4. 计算机相近专业有哪些,计算机相关的专业有哪些
  5. Java Servlet JSP
  6. 5年5亿美金,一年送出 1000 张训练卡,华为昇腾如何吸引AI开发者?
  7. java 栈_Java实现单链表、栈、队列三种数据结构
  8. 侯策:如何突破前端开发技术瓶颈
  9. 19【推荐系统2】矩阵分解算法——协同过滤的进化
  10. IEnumerableIEnumerablestring结构解析通用解决方案(支持指定属性顺序)
  11. 管理感悟:宁可五个阶段做三个月,绝不一个阶段做二个月
  12. 博客园文章索引生成器
  13. 服务器虚拟化2种架构,服务器虚拟化常用架构详解
  14. 网络版瑞星服务器无法升级
  15. 第一次创建STC15串口程序模板
  16. 统计学中的十几个数据分析方法
  17. 多媒体数字互动技术的应用有哪些?
  18. 苹果开发者账号的申请
  19. Archlinux安装yaourt
  20. TCP3次握手为啥挥手却要4次,这下解释明白了

热门文章

  1. GitHub Pages 自定义域名实践整理
  2. Linux数据库密码忘记
  3. Windows下使用HDFView了解ICESat-2的hdf5文件
  4. python外星人入侵游戏代码大全-Python外星人入侵游戏编程完整版
  5. ModuleNotFoundError: No module named 'lightgbm'
  6. 整理的CAPL详细内容
  7. 使用MyBatis实现增删改查遇到的异常解决方法
  8. JAVA不直接使用指针吗_Java不直接使用指针。
  9. 共享店铺系统如何搭建无人共享自习室?
  10. 电脑计算机网络都打不开怎么办,电脑打不开网页怎么办?如何解决电脑网页打不开问题...