C语言代码

luckyFang 2020年10月26日 343次浏览

1.第一个C语言程序.cpp

/*
	这是第一个C语言程序 
*/ 
#include<stdio.h>//头文件 std标准 io输入输出 
int main(){//主函数--程序的入口main 
 //int--->返回值 
	printf("Hello!");//输出语句,表示打印Hello 
	return 0;//返回一个0,表示正常结束;异常结束返回一个
	//非0值 
}
 

2.两个整数求和.cpp

#include<stdio.h>
int main(){
	//程序-->内存 --->执行 
	int a,b,sum;//定义变量,在内存中分配空间 
	a = 100;
	b = 30;//给变量赋值 
	sum = a+b;
	printf("你好sum=%d\n",sum);	
	//"sum=%d\n"输出格式 
	//sum输出的变量 %d表示输出一个整数 
	//\n回车换行
	printf("hello"); 
	return 0;
} 

3.常量.cpp

#include<stdio.h>
int main(){
	//1.整型常量 -100 1000 0
	int a = 100; 
	printf("a=%d\n",a);
	//2.实型常量2.5  34.67
	float b = 12.3;//单精度浮点型
	printf("b=%f\n",b); 
	float c= 12.5e3;//12.5乘以10的3次方
	//e或E都可以
	printf("c=%f\n",c); 
	float d = 2.3e-2;//2.3乘以10的-2次方
	printf("d = %f\n",d);
	//3.字符常量
	char e = '?';
	printf("e = %c\n",e);
	//转义字符
	char f= '\n';//回车换行 
	printf("f = %c\n",f);
	printf("hel\thello\n");
	printf("\c");
	char g ='\110';//八进制对应的字符   65
	printf("g = %c\n",g);
	char h='\x41'; //十六进制对应的字符
	printf("h = %c\n",h);
	//4.字符串常量 
	char i[] = "abcd";
	printf("i=%s\n",i);
	//'a'   "a" 
	return 0;
} 

5.变量.cpp

#include<stdio.h>
int main(){
	int a;//定义变量,在内存中开辟4Byte大小
	a = 10;//给变量赋值 
	//1Byte = 8bit 
	//4Byte = 32bit
	//00000000 00000000 00000000 00000000
	//11111111 11111111 11111111 11111111
	//01111111 11111111 11111111 11111111
	//1111=+7
	//0111=-7
	printf("a=%d\n",a);
	short b = 12;//短整型,在内存中开辟2Byte 
	printf("b=%d\n",b);
	long c = 13;//长整型,内存中开辟4Byte 
	printf("c=%d\n",c); 
	long long d = 13;//双长型, 内存中开辟8Byte
	printf("d=%d\n",d); 
	return 0;
} 

6.无符号数.cpp

#include<stdio.h>
int main(){
	//补码 
	unsigned int a = 100;
	//11111111 11111111 11111111 11111111
	//00000000 00000000 00000000 00000000
	//1111=15
	//0000=0
	printf("a = %d\n",a);
	unsigned int b = -100;
	printf("b = %d\n",b);
	printf("b = %u\n",b);//%u无符号数的输出格式 
	//0110 
	return 0;
} 

7.字符型.cpp

#include<stdio.h>
int main(){
	char ch = 'a';//会在内存中开辟1Byte。 
	//字符在计算机存储的时候,存储的都是字符的ASCII码
	printf("ch = %c\n",ch); 
	printf("ch ascii = %d\n",ch);
	//计算'1'-1的结果? 48
	char ch2 = '1';
	int a = 1;
	printf("%d\n",(ch2-a));
	return 0;
} 

8.字符转化.cpp

#include<stdio.h>
int main(){
	char ch = 'a';//97   A:65   =32
	//小写字符的ascii码和大写字符的ascii码相差32
	char ch2 = ch - 32;
	printf("ch2 = %c",ch2); 
	return 0;
} 

9.浮点数.cpp

#include<stdio.h>
int main(){
	float a = 12.34519872123F;
	printf("a = %.8f\n",a); 
	double b = 12.34519872123;
	printf("b = %.11f\n",b);
	//12.4--double 12.4f--float
	float c = 12.3456;
	//将double的数赋值给float类型,有可能发生数据溢出 
	return 0;
} 

10.算术运算.cpp

#include<stdio.h>
int main(){
	int a = 17;
	int b = 5;
	int c; 
	c = a+b; //=赋值运算符   +算术运算符  
	//算术运算符的优先级高于赋值运算符 
	printf("c= %d\n",c);
	c = a-b;
	printf("c= %d\n",c);
	c = a*b;
	printf("c= %d\n",c);
	c = a/b;//17/5 = 3  int/int=int 
	printf("c= %d\n",c);
	c = a%b;//2.3%2
	printf("c= %d\n",c);
	//%两边的值,必须是整型 
	//printf("c= %d\n",2.3%2.3);错误 
	return 0;
} 

11.++.cpp

#include<stdio.h>
int main(){
	int  a  = 18 ;
	printf("a=%d\n",a++);//1.打印  2.++ 
	printf("a=%d",a); 
	return 0;
} 

12.不同类型的运算.cpp

#include<stdio.h>
int main(){
	int i = 3;
	float f = 3.5f;
	double d = 7.5;
	double dd;//从左到右 
	//1.计算10+'a'=107;107+i*f-d/3
	//2. i*f=10.5;107+10.5-d/3
	//3.107+10.5=117.5;117.5-d/3
	//4.d/3=7.5/3=2.5;117.5-2.5
	//5.115.000000
	printf("dd=%f",dd);
	return 0;
} 

13.强制类型转化.cpp

#include<stdio.h>
int main(){
	float a = 12.8456f;
	int b;
	b = (int)a; 
	printf("b = %d",b);
	return 0;
	//(int)((double)(7/2)+3.5)
	//1.(int)((double)3+3.5)
	//2.(int)(3.0+3.5)
	//3.(int)6.5
	//4.6
	//(int)((double)7/2+3.5)
} 

14.求素数.cpp

#include<stdio.h>
int main(){
	//求100-200之间所有的素数。 
	int flag = 0;//0表示素数  1表示不是素数 
	for(int i=100;i<=200;i++){//101
		flag = 0;
		for(int j = 2;j<=i-1;j++){
			if(i%j==0){
				flag=1;
			} 
		}
		if(flag==0) printf("%5d",i);
	} 
	return 0;	 
} 

15.科学表示.cpp

#include<stdio.h>
int main(){
printf("%-20.15e",10.0/3);
	return 0;
} 

17.printf用法.cpp

#include<stdio.h>
int main(){
	//1.d格式--->输出整型数据 
	printf("No.1:%d\n",122);
	printf("No.2:%5d\n",122);//输出数据占5列(向右对齐)
	printf("No.3:%-5d\n",122);//输出数据占5列(向左对齐)
	//2.c格式--->单个字符 
	printf("No.4:%c\n",'\101');
	//3.f格式--->浮点型数据(float,double)
	printf("No.5:%f\n",3.14);//3.140000
	float a = 10.0f;
	printf("No.6:%20.15f\n",a/3);//占20列,15位小数 
	printf("No.7:%-20.15f\n",a/3);
	//4.e格式--->结果为指数形式
	printf("No.8:%25.15e\n",a/3);
	printf("No.9:%e\n",190.34);
	printf("No.10:%e\n",0.002345);
	//5.o格式-- >将一个数按照8进制输出 
	printf("No.11:%o\n",1001);
	//6.x格式-- >将一个数按照16进制输出 
	printf("No.12:%x\n",1001);
	//7.u格式-->输出一个无符号的数
	printf("No.13:%u\n",1001);
	return 0;
} 

18.scanf.cpp

#include<stdio.h>
int main(){
	int a;
	scanf("a=%d",&a); //输入格式,往什么地方输入
	//&-->取地址符
	printf("a = %d\n",a); 
	printf("a(addr)=%p\n",&a);
	printf("a(addr)=%d\n",&a);
	return 0;
} 

18.scanf2.cpp

#include<stdio.h>
int main(){
	float a,b,c;
	scanf("a=%f,b=%f,c=%f",&a,&b,&c);
	printf("a=%f,b=%f,c=%f",a,b,c);
	return 0;
} 

18.scanf3.cpp

#include<stdio.h>
int main(){
	int a,b,c;
	scanf("%d%d,%d",&a,&b,&c);
	printf("a=%d,b=%d,c=%d",a,b,c);
	//1.每输入一个数据后,加空格
	//2.每输入一个数据后,加回车
	//3. 每输入一个数据后,加tab
	return 0;
} 

18.scanf4.cpp

#include<stdio.h>
int main(){
	char a,b,c;
	scanf("%c%c%c",&a,&b,&c);
	printf("a=%c,b=%c,c=%c",a,b,c);
	//对于字符输入时,每一个字符要紧紧的挨在一起。 
	return 0;
} 

19.putchar.cpp

#include<stdio.h>
int main(){
	char a = 'a';
	char b = 'r';
	char c = 'w';
	int d = 65;
	putchar(a); //将变量a的值输出 
	putchar('\n');
	putchar(b);
	putchar(c);
	putchar('\101');
	putchar(d);
	return 0;
} 

20.getchar.cpp

#include<stdio.h>
int main(){
	char a,b,c;
	a = getchar();//获得到键盘输入的单个字符 
	b = getchar();
	c = getchar();
	putchar(a); 
	putchar(b); 
	putchar(c); 
	return 0;
} 

21.例题.cpp

#include<stdio.h>
int main(){
	int x,y;
	scanf("%d%3d",&x,&y);
	printf("%d %d",x,y); 
	return 0;
} 

22.三角形面积.cpp

#include<stdio.h>
#include<math.h>
int main(){
	//求三角形面积
	//海伦公式
	double a,b,c;//三个边长
	printf("请输出三个边的边长:\n");
	scanf("a=%lf,b=%lf,c=%lf",&a,&b,&c);
	double s,area;
	s = (a+b+c)/2;
	area = sqrt(s*(s-a)*(s-b)*(s-c));//sqrt(3)
	printf("三角形的面积是:%f",area);
	return 0;
}

23.求根.cpp

#include<stdio.h>
#include<math.h>
int main(){
	float a,b,c;
	printf("请输入a,b,c的值:\n");
	scanf("%f,%f,%f",&a,&b,&c);
	float p,q;
	p = -b/(2.0*a); 
	q = sqrt(b*b-4*a*c)/2.0*a;
	float x1,x2;
	x1 = p+q;
	x2 = p-q;
	printf("x1=%f,x2=%f",x1,x2);
	return 0;
}

24.关系运算.cpp

#include<stdio.h>

int main(){
	printf("%d\n",1>2);
	printf("%d\n",100>2);
	printf("%d\n",100!=2);
	printf("%d\n",100>=2);  
	return 0;
}

25.关系运算优先级.cpp

#include<stdio.h>

int main(){
	int a =1,b=3,c=2;
	printf("%d\n",(a==b>c)); 
	//1.b>c  3>2=1
	//2.a==1
	printf("%d\n",(a<=b==c));
	printf("%d\n",(a+1>b==c));
	//1.a+1
	//2.2>b-->0
	//3.0==c
	return 0;
}

26.逻辑运算符.cpp

#include<stdio.h>
int main(){
	printf("%d\n",(1&&1));
	printf("%d\n",(1&&0));
	printf("%d\n",(0&&1));
	printf("%d\n",(0&&0));
	
	printf("%d\n",(1||1));
	printf("%d\n",(1||0));
	printf("%d\n",(0||1));
	printf("%d\n",(0||0));
	
	printf("%d\n",(!0));
	printf("%d\n",(!1));
	return 0;
}

27.逻辑运算符2.cpp

#include<stdio.h>
int main(){
	int a = 10;
	int b = -2;
	printf("%d",(a&&b));
	//非0的数表示真,0表示假 
	return 0;
}

28.逻辑运算符3.cpp

#include<stdio.h>
int main(){
	int a = 2,b=4,c=3,d=7;
	printf("%d\n",a<b||c<d);//1||1--->1
	printf("%d\n",a<b&&c<d);//1
	printf("%d\n",a>b||c<d);//0||1--->1
	printf("%d\n",a<b&&c>d);//1&&0--->0
	printf("%d\n",!a<b&&c>d);//0<4&&c>d-->0
	return 0;
}

29.练习.cpp

#include<stdio.h>
int main(){
	int a = 1,b=9;
	a++||(b = b+100);//2||?=1
	printf("b=%d",b);
	return 0;
}

30.if.else.cpp

#include<stdio.h>
int main(){
	//例如:输入两个整数,由大到小输出。
	int a,b,t;
	scanf("%d%d",&a,&b);//12 6   6 12
	if(a<b){
		t = a;
		a = b;
		b = t;
	} 
	printf("%d,%d",a,b); 
	return 0;
}

32.闰年.cpp

#include<stdio.h>
int main(){
	int year;
	printf("请输入年份:\n");
	scanf("%d",&year);
	if((year%4==0&&year%100!=0)||(year%400==0))
		printf("是闰年!"); 
	else
		printf("不是闰年!"); 
	return 0;
}

33.分段函数.cpp

#include<stdio.h>
int main(){
	double x,y;
	scanf("%lf",&x);
	if(x<1){
		y = x;
	}else if(1<=x&&x<10){
		y=2*x-1;
	}else if(x>=10){
		y = 3*x-11;
	}
	printf("y = %f",y);
	return 0;
}
//if(){}
//if(){}else{}
//if(){}else if(){}else if(){}...else{}
 

34.求最大值.cpp

#include<stdio.h>
int main(){
	int a ,b,max;
	scanf("%d%d",&a,&b);
//	//方法1 
//	if(a>b)
//		max = a;
//	else
//		max = b;
//	printf("max= %d",max);
//方法2
//	max = (a>b)?a:b; 
//	printf("max= %d",max);
//方法3
// (a>b)?max = a:max = b; 
// printf("max= %d",max);
//方法4
	a>b?printf("max=%d",a):printf("max=%d",b); 
	return 0;
}
//输入一个字符,判断它是否是大写字母,如果是大写字母
//转换为小写字母,如果是小写字母,直接输出。 

35.大小写转换.cpp

#include<stdio.h>
//输入一个字符,判断它是否是大写字母,如果是大写字母
//转换为小写字母,如果是小写字母,直接输出。
int main(){
	char ch,c;
	ch=getchar();
	c=(ch>='A'&&ch<='Z')?ch+32:ch; 
	putchar(c);
	return 0;
}

36.switch.cpp

#include<stdio.h>
int main(){
	//用户输入成绩的等级,显示用户的分数
	//A-->85分以上,B->70-84,C->60-69,D->60以下
	char grade;
	scanf("%c",&grade);
	switch(grade){
		case 'A':printf("85分以上");//break跳出 
		case 'B':printf("70-84");break;
		case 'C':printf("60-69");
		case 'D':printf("60以下");break; 
		default:printf("输入错误!");
	}
	//当程序碰到一个匹配的case后 ,会从当前语句开始依次执行
	//直到碰到break语句或switch语句执行完。 
	return 0;
} 

37.一元二次方程.cpp

#include<stdio.h>
#include<math.h>
int main(){
	double a,b,c,disc,x1,x2,p,q; //-0.00000001
	printf("请输入abc的值\n");
	scanf("%lf%lf%lf",&a,&b,&c);
	if(fabs(a)<=1e-6){//a==0
		printf("不是一元二次方程\n");
	}else{
		disc=b*b-4*a*c;
		if(fabs(disc)<=1e-6){//disc==0
			printf("两个相等的实数根:%f\n",(-b/(2*a)));
		}else if(disc>1e-6){//1 2 2 
			x1 = (-b+sqrt(disc))/(2*a);
			x2 = (-b-sqrt(disc))/(2*a);
			printf("no1:%f,no2:%f",x1,x2);
		}else{
			p = -b/(2*a);//实数 
			q = sqrt(-disc)/(2*a);//虚数
			printf("no1:%8.4f+%8.4fi\n",p,q);
			printf("no2:%8.4f-%8.4fi\n",p,q);
		}
	} 
	return 0;
} 

38.while循环.cpp

#include<stdio.h>
int main(){
	//1+2+3+...+100
	int i = 1;
	int sum = 0; 
	while(i<=100){
		sum = sum+i;
		i++;
	}
	printf("sum=%d\n",sum);
	printf("i=%d\n",i);
	//1.i=1 sum=0 i<=100(ok) sum =0+1=1  i=2 
	//2.i<=100(ok) sum = 1+2=3 i=3
	//3.i<=100(ok) sum = 3+3=6 i=4
	//4.i<=100(ok) sum = 6+4=10 i=5
	//....
	//100.i<=100(ok) sum =4950 +100=5050 i=101
	//101.i<=100(false) 跳出循环 
	return 0;
} 

39.do..while.cpp

#include<stdio.h>
int main(){
	//1+2+3+...+100
	int i =1;
	int sum = 0;
	do{
		sum+=i;//sum = sum+i
		i++;
	}while(i<=100);
	printf("sum=%d",sum);
	return 0;
} 

40.while、.cpp

#include<stdio.h>
int main(){
	int i = 1;
	int a = 0;
	while(i<1){
		a = 100;
		i++;
	} 
	printf("a = %d",a);
	return 0;
} 

41.do..while、.cpp

#include<stdio.h>
int main(){
	int i = 1;
	int a = 0;
	do{
		a = 100;
		i++;
	} 
	while(i<1);
	printf("a = %d",a);
	return 0;
} 

42.for循环.cpp

#include<stdio.h>
int main(){
	//1+2+3...+100
	int sum = 0;
	for(int i=1;i<=100;i++){
		sum = sum +i;
	}
	printf("sum = %d",sum);
	return 0;
} 

43.break.cpp

#include<stdio.h>
int main(){
	for(int i=1;i<=10;i++){
		if(i%5==0) continue;
		printf("%d\t",i);
	}
	//1.1
	//2.2
	//3.3
	//4.4
	//5.这一次循环不执行
	//6. 6
	//7.7
	//8.8
	//9.9
	//10.这一次循环不执行
	return 0;
} 

44.不能被3整除.cpp

#include<stdio.h>
int main(){
	for(int i=100;i<=200;i++){
		if(i%3==0) continue;
		printf("%d\n",i);
	}
	return 0;
} 

45.被7整除.cpp

#include<stdio.h>
int main(){
int i,j;
for(i=100,j=0;i<=200;i++)
	if(i%7==0){
		printf("%4d",i);
		j++;
		if(j%5==0) printf("\n");
	} 
	return 0;
} 

46.两层循环.cpp

#include<stdio.h>
int main(){
	int i;//行 
	int j;//列 
	for(i=1;i<=4;i++){//行 
		for(j=1;j<=5;j++){//列 
			printf("%6d",i*j); 
		}
		printf("\n");
	} 
	return 0;
} 

47.水仙花.cpp

#include<stdio.h>
int main(){//234/100=2  345/100=3 6789/1000
	int b,s,g;//百 十 个
	for(int i=100;i<=500;i++){
		b=i/100;
		s=i%100/10;
		g=i%10; 
		if(i==b*b*b+s*s*s+g*g*g) printf("%d是水仙花数",i);
	} 
	return 0;
} 

48.求pi.cpp

#include<stdio.h>
#include<math.h>
int main(){
	int sigin = 1;// 分子
	double n = 1 ;//分母
	double pi =0.0; //pi值
	double term = 1.0; //每一项
	while(fabs(term)>=1e-8){
		pi = pi +term;
		n = n +2;
		sigin = -sigin;
		term=sigin/n;
	} 
	pi = 4*pi;
	printf("%.18f",pi);
	return 0;
} 

49.数组.cpp

#include<stdio.h>

int main(){
	int a[10];//[常量]
	//1.定义了一个整型int数组。在这个数组中,每一个元素
	//都是int类型。
	//2.a表示数组名称,表示数组首元素的地址,并且这个地址为常量 
	//3.10表示数组中有10个int类型的元素,数组中第一个元素的
	//下标为0.
	//4.会在内存中开辟连续的10个空间存放int类型的元素。 
	a[0] = 5; //0-->下标 
	a[1] = 10;
	a[2] = 11;
	//a[6] = 0;
	printf("%d\n",a);//a[0]元素的地址12345 
	printf("%d\n",a[0]);
	printf("%d\n",a+1);//a[1]元素的地址12349
	printf("%d\n",a+2);//a[2]元素的地址
	for(int i=0;i<=9;i++){
		printf("%d\t",a[i]);
	}
	printf("\n");
	for(int i=0;i<=9;i++){
		printf("%d\n",a+i);
	}
	return 0;
}

50.数组基本形式.cpp

#include<stdio.h>

int main(){
	//c# 
	//1.
	int a[10]={1,2,3,4,5,6,7,8,9,0};
	for(int i=0;i<=9;i++){
		printf("%d\t",a[i]);
	}
	printf("\n");
	//2.
	int b[10]={1,2,3,4};
	for(int i=0;i<=9;i++){
		printf("%d\t",b[i]);
	}
	printf("\n");
	//3.
	int c[10] = {0};
	for(int i=0;i<=9;i++){
		printf("%d\t",c[i]);
	}
	printf("\n");
	//4.
	int d[] = {1,2,3,6,7,8};
	for(int i=0;i<=5;i++){
		printf("%d\t",d[i]);
	}
	printf("\n");
	int j = 10;
	int array[j];
	return 0;
}

51.斐波那契数列.cpp

#include<stdio.h>
int main(){
	//斐波那契数列fibonacci 
	//1 1 2 3 5 8 13...
	//用数组求解fibonacci的前20项
	int f[20]={1,1}; 
	for(int i=2;i<=19;i++){
		f[i] = f[i-2]+f[i-1];
	}
	for(int i=0;i<=19;i++){
		if(i%5==0) printf("\n");
		printf("%d\t",f[i]);
	}
	return 0;
}

52.二维数组.cpp

#include<stdio.h>
int main(){
	int a[5][5];//行   列 
	//1.定义了一个整型二维数组,数组中的每一个元素都为
	//整型int元素
	//2.数组有5行5列,a表示首行元素的地址
	//3.二维数组的行、列下标都是从0开始的。
	//4.数组的每一个元素在内存中是按行顺序存放的 
	a[0][0] = 100;
	printf("%d\n",a[0][0]);
	printf("%d\n",a);//第一行元素的地址6487472
	printf("%d\n",a+1);//第二行元素的地址6487492
	printf("%d\n",a[0]);//第一个元素a[0][0]的地址 
	printf("%d\n",a[0]+1);//第二个元素a[0][1]的地址
	printf("%d\n",a[1]+1);//第二行第二列a[1][1]的地址
	return 0;
}

53.二维数组赋值.cpp

#include<stdio.h>
int main(){
	//1.
	int a[3][4] = {{1,2,3,4},{5,6,7,8},{9,0,1,2}}; 
	printf("%d\n",a[2][1]);
	for(int i=0;i<=2;i++){//行 
		for(int j=0;j<=3;j++){//列 
			printf("%d\t",a[i][j]);
		}
		printf("\n");
	}
	//2.
	int b[3][4] = {1,2,3,4,5,6,7,8,9,0,1,2};
	for(int i=0;i<=2;i++){//行 
		for(int j=0;j<=3;j++){//列 
			printf("%d\t",b[i][j]);
		}
		printf("\n");
	}
	//3.
	int c[3][4]={{1,2},{2},{4}}; 
	for(int i=0;i<=2;i++){//行 
		for(int j=0;j<=3;j++){//列 
			printf("%d\t",c[i][j]);
		}
		printf("\n");
	}
	//4.
	int d[3][4]={0};
	for(int i=0;i<=2;i++){//行 
		for(int j=0;j<=3;j++){//列 
			printf("%d\t",d[i][j]);
		}
		printf("\n");
	}
	//5.
	int e[][4]={1,2,3,4,5,6,7,8,9,10,11,12};
	//int e[3][]={1,2,3,4,5,6,7,8,9,10,11,12};错误!
	//int e[][]={1,2,3,4,5,6,7,8,9,10,11,12};错误! 
	for(int i=0;i<=2;i++){
		for(int j=0;j<=3;j++){
			printf("%5d",e[i][j]);
		}
		printf("\n");
	}
	 
	return 0;
}

54.数组例题.cpp

#include<stdio.h>
int main(){
	int a[10]; 
	//1.输入10个数 
//	for(int i=0;i<=9;i++){//&a[0]
//		scanf("%d",&a[i]); 
//	} 
	for(int i=0;i<=9;i++){//a+1
		scanf("%d",a+i);
	}
	//2.求平均分
	float avg,sum = 0; 
	for(int i=0;i<=9;i++){
		sum = sum +a[i];
	}
	avg = sum/10;
	//3.统计比平均分少的个数
	int j = 0; 
	for(int i=0;i<=9;i++){
		if(avg>a[i]) j++;
	}
	printf("%d,%f",j,avg);
	return 0;
}

55.字符数组.cpp

#include<stdio.h>
int main(){
	//1.字符数组 
	char a[10] = {'I',' ','l','o','v','e'}; 
	for(int i=0;i<=9;i++){
		printf("%c\n",a[i]); 
	} 
	//2.
	char b[]={"hello"};//字符串 
	//字符串b在内存中占了多少空间?6Byte
	//字符串b的有效字符数为?5 
	printf("%d\n",sizeof(b)); //
	for(int i=0;i<=5;i++){
		printf("%c",b[i]); 
	} 
	printf("\n",b);
	printf("%s\n",b);
	//3.
	char c[] = "hellohello"; 
	printf("%s",c);
	return 0;
}

56.字符串.cpp

#include<stdio.h>
int main(){
	char a[] = "helloworld!";//\0
	printf("%s\n",a);
	a[5] = '\0';
	printf("%s",a);
//	for(int i=0;a[i]!='\0';i++){
//		printf("%c",a[i]);
//	}
	return 0;
}

57.字符串的输入.cpp

#include<stdio.h>
int main(){
	char str1[5],str2[5],str3[5];
	//str1
	scanf("%s%s%s",str1,str2,str3); 
	printf("str1=%s,str2=%s,str3=%s",str1,str2,str3);
	//输入方式1:she he she
	//输入方式2:she   he   she
	//输入方式3:she回车he回车she 
	return 0;
}

58.字符串操作函数.cpp

#include<stdio.h>
#include<string.h>
int main(){//string---字符串 
	char str1[] ="I love china!";
	//1.输出字符串
	puts(str1); //同printf("%s",str1);
	//2.输入一个字符串
//	char str2[10];
//	gets(str2);
//	puts(str2);
	//3.字符串连接函数strcat(字符串1,字符串2);
	//功能:将字符串2,拼接到字符串1中。
	char str3[] = "hello"; 
	char str4[] = "world";
	strcat(str3,str4);//
	puts(str3);
	puts(str4);
	//4.字符串的复制strcpy(字符串1,字符串2)
	//功能:将字符串2复制到字符串1中。 
	char str5[10];
	char str6[]="hello";
	strcpy(str5,str6);
	puts(str5); 
	//str5=str6;
	//5.字符串比较函数strcmp(字符串1,字符串2)
	//两个字符串相等,返回0;
	//字符串1<字符串2,返回-1;
	//字符串1>字符串2,返回1; 
	//1.按照字典的顺序比较大小的,越往后越大
	//2.小写字母>大写字母  a>A
	//3.如果出现不同的字符串,以第一个不同的字符比较为准
	char str7[] ="helloa";
	char str8[]="hellob";
	printf("%d\n",strcmp(str7,str8)); 
	//6.检查字符串的实际长度strlen()
	char str9[] = "hello";//5 
	printf("%d\n",strlen(str9));//实际长度? 
	printf("%d\n",sizeof(str9));//占多大空间?
	//7.将字符串转换为小写strlwr() lowercase
	char str10[] ="BBBB";
	strlwr(str10);
	puts(str10);
	//8.将字符串转换为大写 strupr() upercase
	strupr(str10);
	puts(str10);
	return 0;
}

59.二维数组例题.cpp

#include<stdio.h>
int main(){
	//1.定义二维数组
	int a[4][4] = {{23,44,12,77},{13,2,33,12}
	,{23,45,12,65},{11,9,15,78}}; 
	//2.定义需要的变量
	int sum = 0;
	//3.算法---- 遍历 
	for(int i=0;i<=3;i++){
		for(int j=0;j<=3;j++){
			if(a[i][j]>max) {
			max = a[i][j];
			x = i;
			y = j;
			} 
		}
	} 
	printf("max=%d,i=%d,j=%d",max,x,y);
	return 0;
} 

60.二维数组例题2.cpp

#include<stdio.h>
int main(){
	int a[10][10]={0};
	for(int i=0;i<=9;i++){
		a[i][0] = 1;
		a[i][i] = 1;
	}
	for(int i=2;i<=9;i++){
		for(int j=1;j<=9;j++){
			a[i][j] = a[i-1][j-1]+a[i-1][j];
		}
	}
	for(int i=0;i<=9;i++){
		for(int j=0;j<=i;j++){
			printf("%5d",a[i][j]);
		}
		printf("\n");
	} 
	return 0;
} 

61.最大公约数.cpp

#include<stdio.h>
int main(){ 
	printf("请输入两个值\n");
	int m;
	int n;
	scanf("%d%d",&m,&n);
	//1.找m和n最小的那个数
	int temp;//保存最小的那个数
	if(m>n) temp =n;
	else temp =m;
	//2.从最小值开始除,直到m和n第一次被同时整除,跳出循环
	int i;
	for(i = temp;i>0;i--){
		if(m%i==0&&n%i==0){
		printf("最大公约数为:%d\n",i);	break;
		}
	} 
	int lcm;//
	lcm = m * n /i;
	printf("最小公倍数为:%d\n",lcm);
	return 0;
} 

62.求素数.cpp

#include<stdio.h>
int main(){
	int n;//要判断的这个数 
	scanf("%d",&n);
	int i;
	for(i=2;i<=n-1;i++){
		if(n%i==0) break;
	} 
	//n=5
	//i=2  2<=4 (ok) 5%2
	//i=3  3<=4(ok)  5%3
	//i=4  4<=4(ok)  5%4
	//i=5
	if(i<n) printf("不是素数\n");
	else printf("是素数\n"); 
	return 0;
	//求100-200之间所有的素数。 
} 

63.函数.cpp

#include<stdio.h>
int main(){
	//2.函数的声明--告诉编译器,定义了一个函数
	void print_info();
	//3.使用函数(调用函数) 
	print_info();
	print_info();
	return 0;	 
}
//1.定义自定义函数 
void print_info(){//void返回值(空)  print_info函数名称 
//()无参的函数 
	printf("hello world!\n");//函数的操作 
} 

64.函数2.cpp

#include<stdio.h>
//1.定义自定义函数 
void print_info(){//void返回值(空)  print_info函数名称 
//()无参的函数 
	printf("hello world!\n");//函数的操作 
} 
int main(){
	//2.使用函数(调用函数) 
	print_info();
	print_info();
	return 0;	 
}

65.函数.cpp

#include<stdio.h>
int main(){
	void print_info();
	int sum(int,int);//int sum(int a,int b);
	
	print_info();
	int x =3;
	int y = 4;
	int s = sum(x,y);//实参 (实际参数) 
	printf("s = %d",s);
	return 0;	 
}
void print_info(){
	printf("hello world!\n");
} 
//求两个整数的和 
//形参 
int sum(int a,int b){//函数执行完后,会带出int类型的值。 
	int c = a+b;
	return c;
} 

66.函数例题.cpp

#include<stdio.h>

int main(){
	int max(int,int);
	printf("请输入两个整数\n");
	int a,b;
	scanf("%d%d",&a,&b); 
	int s = max(a,b);
	printf("s = %d",s);
	return 0;	 
}
int max(int a,int b){
	int z;
	if(a>b){
		z = a;
	}else{
		z = b; 
	} 
	return z;
}


67.函数例题2.cpp

#include<stdio.h>
int main(){
	void fun(int);
	int a = 1;
	fun(a);
	printf("%d",a); 
	return 0;	 
}
void fun(int a){
	a = 100;
}

68.函数例题3.cpp

#include<stdio.h>
int main(){
	float max(float a,float b);
	float a,b;
	scanf("%f%f",&a,&b);
	int s = max(a,b);
	printf("%d",s);
	return 0;	 
}
int max(float a,float b){
	return a>b?a:b;
}

69.函数嵌套.cpp

#include<stdio.h>
int main(){
	int max4(int,int,int,int);//1 
	int a=1,b=4,c=20,d=13;//2 
	int max = max4(a,b,c,d);//3 
	printf("max = %d",max);//19 
	return 0;//20 
}
int max4(int a,int b,int c,int d){//4 
	int max2(int,int);//声明 5 
	int m = max2(a,b);//6 
	m = max2(m,c);//10 
	m = max2(m,d);//14 
	return m;//18 
}
int max2(int a,int b){//7 11 15 
	if(a>b) return a;//8 12 16 
	else return b;//9 13 17 
} 

70.函数递归.cpp

#include<stdio.h>
int main(){
	//5! = 5*4*3*2*1
	int n = 1;
	for(int i=1;i<=5;i++){
		n = n * i;
	}
	printf("%d",n);
	return 0;	 
}

71.函数递归2.cpp

#include<stdio.h>
int main(){
	int fun(int n);
	int s = fun(5);
	printf("%d",s);
	return 0;	 
}
int fun(int n){
	int f;
	if(n==1||n==0){
		f = 1;
	}else if(n>=2){
		f = fun(n-1)*n;
	}
	return  f;
}

72.函数递归3.cpp

//1+2+3+....+100
#include<stdio.h>
int main(){
int age(int n);
int age1 = age(5);
printf("age = %d",age1);
	return 0;	 
}
int age(int n){
	if(n==1) return 10;
	else return age(n-1)+2;
}

73.函数递归4.cpp

//1+2+3+....+100   sum() 
//sum(100)=sum(99)+100
//sum(99)=sum(98)+99
//sum(n)=sum(n-1)+n
//sum(1)=1
#include<stdio.h>
int main(){
	int sum(int n);
	int sum1 = sum(100);
	printf("%d",sum1);
	return 0;	 
}
int sum(int n){
	if(n==1) return 1;
	else return sum(n-1)+n;
}

74.函数递归5.cpp

#include<stdio.h>
int main(){
	int apple(int n,int k);
	int s = apple(3,5);
	printf("%d",s);
	return 0;	 
}
int apple(int n,int k){//表示n的k次方 
	if(k==0) return 1;
	else return apple(n,k-1)*n; 
}

75.函数数组.cpp

#include<stdio.h>
int main(){
	int com(int,int);
	int a[10] = {2,6,10,4,8,30,14,19,20,11}; 
	int max = a[0];//a a+2  &a[4]
	int i = 0;
	for(int j=1;j<=9;j++){
		if(com(max,a[j])>max) {
			max = com(max,a[j]);
			i = j;}	}
	printf("max = %d,index = %d",max,i);
	return 0;	 
}
int com(int a,int b){
	if(a>b) return a;
	else return b;
}

76.数组名作为函数形参.cpp

#include<stdio.h>
int main(){
	void fun(int[]);
	int a[5] ={1,2,3,4,5}; 
	for(int i=0;i<=4;i++){
		printf("%5d",a[i]);
	}
	printf("\n");
	fun(&a[0]);//a
	for(int i=0;i<=4;i++){
		printf("%5d",a[i]);
	}
	return 0;	 
}//引用传递 
void fun(int b[]){//int b[]--->只能接收地址 
	b[4] = 100;
} 

77.数组名作为函数形参2.cpp

#include<stdio.h>
int main(){
	void fun1(int);
	void fun2(int[]);
	int x = 10;
	fun1(x);//单向传递的值 
	printf("x = %d\n",x);
	int y = 10;
	fun2(&y);//单向传递的地址 
	printf("y = %d\n",y);
	return 0;	 
}
void fun1(int a){
	a = 100;
} 
void fun2(int a[]){
	a[0] = 100;
}

78.局部变量.cpp

#include<stdio.h>
int main(){
	//.....
	int a=1,b=2,c=6;
	printf("a=%d,b=%d,c=%d",a,b,c); 
	return 0;	 
}
int fun(int a){
	//....
	int b;
	int c; 
}

79.局部变量2.cpp

#include<stdio.h>
int main(){
	int i =10;
	for(i=0;i<=10;i++){
		printf("%d\n",i);
	}
	printf("%d\n",i);
	return 0;	 
}


80.全局变量.cpp

#include<stdio.h>
int P = 1,Q =10; 
void fun1(){
	int P=100,Q=100;
	printf("P=%d,Q=%d\n",P,Q);
}
int A= 4,B =10;
void fun2(){
	printf("A=%d,B=%d\n",A,B);
}
int main(){
	fun1();
	fun2();
	printf("P=%d,Q=%d\n",P,Q);
	return 0;	 
}


81.真题1.cpp

#include<stdio.h>
#include<math.h>
int main(){
	double Fun2(double error);
	double s = Fun2(1e-6);
	printf("%.16f",s);
	return 0;	 
}
double Fun2(double error){//Fun2(1e-6)
	int sign = 1;//分子
	double n = 1.0;//分母 
	double term = 1.0;// 分子/分母 
	double pi = 0;
	while(fabs(term)>=error) {
		pi = pi +term;
		sign = -sign;
		n = n +2;
		term = sign/n;
	}
	pi = 4*pi;
	return pi;
} 

82.真题2.cpp

#include<stdio.h>
int main(){
	float a = 2;//分子 
	float b = 1;//分母
	float sum = 0.0f;//和
	for(int i=1;i<=20;i++){
		sum = sum+a/b;
		a = a+b;//新的分子 
		b = a-b;//新的分母 
	} 
	printf("%f",sum);
	//1.sum = 0+2/1  a = 3 b =2
	//2.sum = 0+2/1+3/2 a=5 b=3
	//3.sum = 0+2/1+3/2+5/3
	return 0;	 
}


83.真题3.cpp

#include<stdio.h>
int main(){
	float a[20];//分子
	a[0] = 2;a[1] = 3;
	for(int i=2;i<=19;i++){
		a[i] = a[i-1]+a[i-2];
	} 
	float b[20];//分母
	b[0] = 1;b[1] = 2;
	for(int i=2;i<=19;i++){
		b[i] = b[i-1]+b[i-2];
	}
	float sum = 0;
	for(int i=0;i<=19;i++){
		sum = sum +a[i]/b[i];
	}
	printf("%f",sum);
	return 0;	 
}


84.变量存储方式.cpp

#include<stdio.h>
int main(){
	int fun(int x);
	printf("%d\n",fun(1));//12
	printf("%d\n",fun(1));
	printf("%d\n",fun(1));
	return 0;	 
}
int fun(int x){
	static int a = 10;
	a=a+1;
	return (a+x);
}

85.指针.cpp

#include<stdio.h>
int main(){
	int a =100;
	printf("a=%d\n",a);
	printf("a的地址:%d\n",&a);
	return 0;	 
}

86.指针2.cpp

#include<stdio.h>
int main(){
	int a =100;
//	int *p1;//定义了一个指针变量
//	p1 = &a;
	int*   p1 = &a;
	*p1 = 88; 
	printf("a = %d\n",a);
	printf("a = %d\n",&a);
	printf("a = %d\n",p1);
	printf("a = %d\n",*p1);
	return 0;	 
}

87.指针3.cpp

#include<stdio.h>
int main(){
	int a =10,b=20;
	int *p1;int *p2; 
	p1 = &a;p2 = &b;
	int c;
	int *p=&c;
	if(a<b){
		*p =*p1;*p1 =*p2;
		*p2=*p;
	}
	printf("max=%d,min=%d\n",*p1,*p2);
	printf("max=%d,min=%d\n",a,b);
	printf("%d\n",*p);
	return 0;	 
}

88.指针4.cpp

#include<stdio.h>
int main(){
	void swap(int*,int*);
	int a = 10,b=20;
	int *p1=&a;
	int *p2 = &b;
	if(a<b) swap(p1,p2);
	printf("max=%d,min=%d\n",a,b);
	return 0;	 
}
//如果指针变量作为形参,实参向形参传递地址 
void swap(int *p1,int *p2){
	int *p;
	p = p1;
	p1 = p2;
	p2 = p;
}

89.指针5.cpp

#include<stdio.h>
int main(){
	int a[10] ={3,1,2,8,6,1,6,10,7,8}; 
	//a    a[0]//a+1  a[1]
	int *p;
	p = a;
	printf("%d\n",a);
	printf("%d\n",p);
	printf("%d\n",a+1);
	printf("%d\n",p+1);
	printf("%d\n",a[1]);
	printf("%d\n",*(p+1));
	printf("%d\n",a[3]);
	printf("%d\n",*(p+3));
	printf("%d\n",*(a+3));
	return 0;	 
}

90.指针6.cpp

#include<stdio.h>
int main(){
	int a[10] ={3,1,2,8,6,1,6,10,7,8}; 
	for(int i=0;i<=9;i++){
		printf("%d\t",a[i]);
	}
	printf("\n");
	for(int i=0;i<=9;i++){
		printf("%d\t",*(a+i));
	}
	printf("\n");
	int *p = a;
	for(int i=0;i<=9;i++){
		printf("%d\t",*(p+i));
	}
	return 0;	 
}

91.指针7.cpp

#include<stdio.h>
int main(){
	int a[5]; 
	int *p;
	p = a;
	for(int i=0;i<=4;i++){
		scanf("%d",p);
		p = p+1;//p++
	}
	p = a;
	for(int i=0;i<=4;i++){
		printf("%d\t",*(p+i));
	}
	return 0;	 
}

92.真题1.cpp

#include<stdio.h>
int main(){
	void  inv(int a[],int n);
	int a[10] = {1,2,3,4,5,6,7,8,9,0};
	int *p = a;//int *p = &a[0];
	for(int i=0;i<=9;i++){
		printf("%d\t",*(p+i));
	} 
	printf("\n");
	inv(a,10);
	for(int i=0;i<=9;i++){
		printf("%d\t",*(p+i));
	} 
	return 0;	 
}
void  inv(int a[],int n){
	int i;//数组前半部分的下标 
	int j; //数组后半部分的下标
	int temp;//临时空间
	int m =  n/2; //101/2=50交换次数
	for(i=0;i<m;i++){
		j=n-1-i;//9=10-1=n-1-0   8=n-1-1  7=n-1-2 6=n-1-3
		temp = a[i];
		a[i] = a[j];
		a[j] = temp;
	} 
}

93.真题2.cpp

#include<stdio.h>
int main(){
	void  inv(int *a,int n);
	int a[10] = {1,2,3,4,5,6,7,8,9,0};
	int *p = a;
	for(int i=0;i<=9;i++){
		printf("%d\t",*(p+i));
	}
	printf("\n");
	inv(a,10);
	for(int i=0;i<=9;i++){
		printf("%d\t",*(p+i));
	}
	return 0;	 
}
void  inv(int *a,int n){
	int *i,*j;
	i = a;//指针i指向数组的第一个元素
	j = a+n-1; //指针j指向数组的最后一个元素
	int m = n/2; 
	for(;i<(a+m);i++,j--){
		int temp = *i;
		*i = *j;
		*j = temp;
	}
}

94.指针字符串.cpp

#include<stdio.h>
int main(){
	char str1[] = "helloworld"; 
	//str1表示元素h的地址 \0结尾 
	printf("%s\n",str1); 
	//指针字符串 
	char *str2 = "I love you!"; 
	//str2表示字符串第一个元素I的地址,
	//也就是说,指针str2指向元素I,字符串以\0结尾. 
	printf("%s\n",str2);
	printf("%c\n",*str2);
	printf("%c\n",*(str2+3));
	char s[20] = "beijing";
	char *p;
	p = s+1;
	printf("%c\n",p[0]);
	printf("%c\n",*p);
	printf("%c\n",*(s+1));
	printf("%c\n",s[1]);
	return 0;	 
}

95.指针字符串2.cpp

#include<stdio.h>
int main(){
	char a[] = "student";//\0
	char b[20];
	char *p1,*p2;
	p1 = a;
	p2 = b;
	for(;*p1!='\0';p1++,p2++){
		*p2 = *p1;
	}
	*p2 = '\0';
	printf("%s",b);
	return 0;	 
}

96.真题.cpp

#include<stdio.h>
int main(){
	void fun(char *a,int *b);
	char *a = "asdfgFGHJK45678";
	int num = 0;
	fun(a,&num);
	printf("%d",num);
	return 0;	 }
void fun(char *a,int *b){
	int i = 0; int n=0;
	while(*(a+i)!='\0'){
		if(*(a+i)>='a'&&*(a+i)<='z') n++;
		i++;}
	*b = n;
}

97.二维数组的指针.cpp

#include<stdio.h>
int main(){
	int a[3][4] = {{1,2,3,4},{5,6,7,8},{4,3,2,1}};
	printf("%d\n",a); //第0行元素的地址
	printf("%d\n",a+1);//第1行元素的地址
	printf("%d\n",&a[0][0]);//第0行第0列元素的地址
	printf("%d\n",*(a+0)+0);//第0行第0列元素的地址 
	printf("%d\n",*(*(a+0)+0));//第0行第0列元素的值
	printf("%d\n",*(*(a+2)+2));//第2行第2列元素的值
	printf("%d\n",*(a+1)+2);//第1行第2列元素的地址
	printf("%d\n",*(*(a+1)+2));//第1行第2列元素的值
	printf("%d\n",*a+1);//第0行第1列元素的地址 
	printf("%d\n",*(*a+1));//第0行第1列元素的值 
	printf("%d\n",a[1]+1);//第1行第1列元素的地址
	printf("%d\n",*(a[1]+1));//第1行第1列元素的值 
	printf("%d\n",a[1][1]);//第1行第1列元素的值 
	printf("%d\n",a[0]);//第0行第0列元素的地址 
	printf("%d\n",*(a[0]));//第0行第0列元素的值
	return 0;	 
	}


98.二维数组的指针2.cpp

#include<stdio.h>
int main(){//RGB 
	int a[3][4] = {{1,2,3,4},{5,6,7,8},{4,3,2,1}};
	int *p;//指向一个元素 
	p = &a[0][0];// p = a[0];p = *a
	for(;p<a[0]+12;p++){//p = p+1
		if((p-a[0])%4==0) printf("\n");
		printf("%d\t",*p);
	}
	return 0;	 
}


99.二维数组的指针3.cpp

#include<stdio.h>
int main(){//RGB 
	int a[3][4] = {{1,2,3,4},{5,6,7,8},{4,3,2,1}};
	int (*p)[4];//表示指向行的指针,这一行有4个元素。
	p = a;
	int i,j; 
	for(i=0;i<=2;i++){
		for(j=0;j<=3;j++){
		printf("%4d",*(*(p+i)+j));	
		}
		printf("\n");
	}
	return 0;	 
}

100.函数指针.cpp

#include<stdio.h>
int main(){//RGB 
	int max(int,int);
	int add(int,int);
	int (*p)(int,int);//可以指向一个函数的指针。
	//返回值为int类型,并且有 2个参数,并且每个参数的
	//类型为int的函数 
	p = max; //函数的名称表示,函数的地址 
	int z = (*p)(7,8); 
	printf("%d\n",z);
	p = add;
	z = (*p)(7,8);
	printf("%d\n",z);
	return 0;	 
}
int max(int x,int y){
//	if(x>y)return x;
//	else return y;
	int z = (x>y)? x:y;
	return z; 
} 
int add(int x,int y){
	return (x+y);
}

101.指针函数.cpp

#include<stdio.h>
#include<stdlib.h> 
int main(){
	int *p1;
	//p1 = (int *)malloc(20); //分配5个int类型大小的空间 
	p1 = (int *)malloc(sizeof(int)*5); 
	for(int i=0;i<=4;i++){
		scanf("%d",p1+i);
	}
	for(int i=0;i<=4;i++){
		printf("%d\n",*(p1+i));
	}
	return 0;	 
}

102.结构体.cpp

#include<stdio.h>
#include<string.h>
struct Student {
	int num;//学号
	char name[20];//姓名
	char sex;//性别
	char addr[30];//地址 
};
int main(){
	//int i;
	struct Student stu_1;
	stu_1.num = 200101;
	//strcpy()
	strcpy(stu_1.name,"zhangsan");
	stu_1.sex = 'F';
	strcpy(stu_1.addr,"taiyuan");
	printf("%d %s %c %s\n",
	stu_1.num,stu_1.name,stu_1.sex,stu_1.addr);
	struct Student stu_2;
	stu_2.num = 200102;
	//strcpy()
	strcpy(stu_2.name,"lisi");
	stu_2.sex = 'M';
	strcpy(stu_2.addr,"beijing");
	printf("%d %s %c %s",
	stu_2.num,stu_2.name,stu_2.sex,stu_2.addr);
	return 0;	 
}

103.结构体2.cpp

#include<stdio.h>
int main(){
	struct Student {
	int num;//学号
	char name[20];//姓名
	char sex;//性别
	char addr[30];//地址 
	}stu_1={201001,"zhangsan",'F',"beijing"};
	printf("%d %s %c %s\n",
	stu_1.num,stu_1.name,stu_1.sex,stu_1.addr);
	return 0;	 
}

103.结构体3.cpp

#include<stdio.h>
int main(){
	struct{
	int num;//学号
	char name[20];//姓名
	char sex;//性别
	char addr[30];//地址 
	}stu_1={201001,"zhangsan",'F',"beijing"};
	printf("%d %s %c %s\n",
	stu_1.num,stu_1.name,stu_1.sex,stu_1.addr);
	return 0;	 
}

104.结构体数组.cpp

#include<stdio.h>
	struct Student{
	int num;//学号
	char name[20];//姓名
	char sex;//性别
	char addr[30];//地址 
	}; 
int main(){
	struct Student stu[5]={
	{200201,"zhangsan",'F',"taiyuan"},
	{200202,"lisi",'F',"taiyuan"},
	{200203,"wangwu",'M',"taiyuan"},
	{200204,"zhaoliu",'F',"taiyuan"},
	{200205,"sunqi",'M',"taiyuan"}};
	for(int i=0;i<=4;i++){
		printf("%d %s %c %s\n",
		stu[i].num,stu[i].name,stu[i].sex,stu[i].addr);	
	}
	return 0;	 
}

105.结构体指针.cpp

#include<stdio.h>
#include<string.h>
	struct Student{
	int num;//学号
	char name[20];//姓名
	char sex;//性别
	char addr[30];//地址 
	}; 
int main(){
	struct Student stu_1; 
	struct Student *p;
	p = &stu_1;
	stu_1.num = 200101;
	strcpy(stu_1.name,"zhangsan");
	stu_1.sex = 'F';
	strcpy(stu_1.addr,"taiyuan");
	printf("%d %s %c %s\n",
	stu_1.num,stu_1.name,stu_1.sex,stu_1.addr);
	printf("%d %s %c %s\n",
	(*p).num,(*p).name,(*p).sex,(*p).addr);
	printf("%d %s %c %s\n",
	p->num,p->name,p->sex,p->addr);
	return 0;	 
}

106.typedef.cpp

#include<stdio.h> 
typedef int mao;
typedef float gou;
typedef double aaa;
int main(){
	mao a = 100;
	printf("%d\n",a);
	int b = 101;
	printf("%d\n",b);
	return 0;	 
}

107.typedef2.cpp

#include<stdio.h> 
#include<string.h>
typedef struct {
	int num;//学号
	char name[20];//姓名
	char sex;//性别
	char addr[30];//地址 
}abc;
int main(){
	abc stu_1;
	stu_1.num = 200101;
	strcpy(stu_1.name,"zhangsan");
	stu_1.sex = 'F';
	strcpy(stu_1.addr,"taiyuan");
	printf("%d %s %c %s\n",
	stu_1.num,stu_1.name,stu_1.sex,stu_1.addr);
	return 0;	 
}

未命名6.cpp

#include<stdio.h>
#include<string.h> 
int main(){
//	char s[20]="dasdsad";
//	char s1[20]={"dasdsad"};
//	char *s2;
//	s2 = {"sdasadsa"};
//	char *s3;
//	s3 = "sdasadsa";
//	char *s4= "sdasadsa";
//	char *s5= {"sdasadsa"}; 
	char *s = "abcde";
	s+=2;//s =s+2;
	printf("%d\n",s);
	char str[] ="hello!";
	printf("%d\n",strlen(str));
	printf("%d\n",sizeof(str));
	return 0;	 
}