随笔分类 -  C语言学习

上一页 1 2 3 下一页

摘要:1 #include 2 int max(int x,int y){ 3 if(x>y){ 4 return x; 5 } 6 return y; 7 } 8 9 int min(int x,int y){ 10 if(x<y){ 11 return x; 12 } 13 return y; 14... 阅读全文

posted @ 2018-06-28 11:28 孙悟空son_ku_kong 阅读(160) 评论(0) 推荐(0)

摘要:1 //用字符串指针作为函数参数,试下字符串的复制 2 #include 3 void cpystr(char *pss,char *pds){ 4 while( (*pds=*pss)!='\0' ){ 5 pss++; 6 pds++; 7 } 8 } 9 10 int main(){ 11 char *pss="... 阅读全文

posted @ 2018-06-28 11:27 孙悟空son_ku_kong 阅读(119) 评论(0) 推荐(0)

摘要:1 //输出字符串中第n个字符后的所有字符 2 #include 3 int main(){ 4 int n=10; 5 char *str="This is a book"; 6 str=str+n; 7 printf("%s\n",str); 8 return 0; 9 } 阅读全文

posted @ 2018-06-28 11:26 孙悟空son_ku_kong 阅读(81) 评论(0) 推荐(0)

摘要:1 //利用指针的方式输出二位数组的值 2 #include 3 int main(){ 4 int arr[3][4]={ 5 {0,1,2,3}, 6 {4,5,6,7}, 7 {8,9,10,11} 8 }; 9 int (*p)[4]; 10 p=arr; 11 for(int i=... 阅读全文

posted @ 2018-06-28 11:25 孙悟空son_ku_kong 阅读(110) 评论(0) 推荐(0)

摘要:1 //使用指针法,利用数组名计算地址引用数字元素 2 #include 3 int main(){ 4 int a[10]; 5 for(int i=0;i<10;i++){ 6 *(a+i)=i; 7 } 8 for(int j=0;j<10;j++){ 9 printf("%4d",*(a+j)); 10 ... 阅读全文

posted @ 2018-06-28 10:56 孙悟空son_ku_kong 阅读(102) 评论(0) 推荐(0)

摘要:1 //编写用指针变量做参数的函数,将输入的两个整数按从大到小顺序输出 2 #include 3 void swap(int *p1,int *p2){ 4 int temp; 5 temp=*p1; 6 *p1=*p2; 7 *p2=temp; 8 } 9 int main(){ 10 int a,b; 11 int *p1,*... 阅读全文

posted @ 2018-06-28 10:55 孙悟空son_ku_kong 阅读(122) 评论(0) 推荐(0)

摘要:1 //用指针,输入整数a和b,按从大到小的顺序输出a和b 2 #include 3 int main(){ 4 int *p1,*p2,*p,a,b; 5 printf("请输入两个数字\n"); 6 scanf("%d %d",&a,&b); 7 printf("%d %d\n",a,b); 8 p1=&a; 9 p2=&b;... 阅读全文

posted @ 2018-06-28 10:53 孙悟空son_ku_kong 阅读(114) 评论(0) 推荐(0)

摘要:下面是文件file.cpp的源代码 下面是文件main.cpp的源代码 阅读全文

posted @ 2018-06-28 10:52 孙悟空son_ku_kong 阅读(114) 评论(0) 推荐(0)

摘要:1 //static的用法 2 #include 3 void f(int a){ 4 static int b=2; 5 b=a+b; 6 printf("a=%d,b=%d\n",a,b); 7 } 8 9 int main(){ 10 int a=1,i; 11 for(i=1;i<=3;i++){ 12 f(a)... 阅读全文

posted @ 2018-06-28 10:50 孙悟空son_ku_kong 阅读(97) 评论(0) 推荐(0)

摘要:1 //利用递归求!n 2 #include 3 double fact(int n){ 4 double s; 5 if(n==0 || n==1){ 6 s=1; 7 }else{ 8 s=n*fact(n-1); 9 } 10 return s; 11 } 12 13 int main(){ 14 ... 阅读全文

posted @ 2018-06-28 10:49 孙悟空son_ku_kong 阅读(110) 评论(0) 推荐(0)

摘要:1 //输入N个字符,查找最大的字符串 2 #include 3 #include 4 int main(){ 5 char s[6][100]; 6 printf("请输入6个字符串\n"); 7 for(int j=0;j<6;j++){ 8 gets(s[j]); 9 } 10 int max=0; 11 f... 阅读全文

posted @ 2018-06-28 10:48 孙悟空son_ku_kong 阅读(110) 评论(0) 推荐(0)

摘要:1 //统计字符串中的英文单词的数目 2 #include 3 #include 4 int main(){ 5 char s[100]; 6 printf("请输入字符串\n"); 7 gets(s); 8 int i=0,word=0,num=0; 9 for(;s[i]!='\0';i++){ 10 if(s[i]=... 阅读全文

posted @ 2018-06-28 10:46 孙悟空son_ku_kong 阅读(93) 评论(0) 推荐(0)

摘要:1 //判断回文 2 #include 3 #include 4 int main(){ 5 char s1[100]; 6 printf("请输入字符串\n"); 7 gets(s1); 8 int n=0; 9 for(;s1[n]!='\0';n++){ 10 11 } 12 n--; 13 int fla... 阅读全文

posted @ 2018-06-28 10:45 孙悟空son_ku_kong 阅读(125) 评论(0) 推荐(0)

摘要:1 //比较两个字符串 2 #include 3 #include 4 int main(){ 5 char s1[100],s2[100]; 6 int i; 7 printf("请输入字符串1\n"); 8 gets(s1); 9 printf("请输入字符串2\n"); 10 gets(s2); 11 if(strc... 阅读全文

posted @ 2018-06-28 10:44 孙悟空son_ku_kong 阅读(134) 评论(0) 推荐(0)

摘要:1 //运用strcat函数 2 #include<stdio.h> 3 #include<string.h> 4 int main(){ 5 char s1[100]="Tianjing,",s2[]="How are you"; 6 strcat(s1,s2); 7 puts(s1); 8 re 阅读全文

posted @ 2018-06-27 18:43 孙悟空son_ku_kong 阅读(117) 评论(0) 推荐(0)

摘要:1 //char s1[100],s2[]="How are you!" 2 //s1=s2;错误!因为s1表示数组的第0个元素的地址,它为常量,不能被赋值 3 #include 4 #include 5 int main(){ 6 char s1[100],s2[]="How are you"; 7 strcpy(s1,s2); 8 puts(s1)... 阅读全文

posted @ 2018-06-27 18:42 孙悟空son_ku_kong 阅读(117) 评论(0) 推荐(0)

摘要:1 #include 2 #include 3 int main(){ 4 char s[100]; 5 gets(s); 6 printf("原字符串:%s\n",s); 7 printf("变大写字符串%s\n",strupr(s)); 8 printf("变小写字符串%s\n",strlwr(s)); 9 return ... 阅读全文

posted @ 2018-06-27 18:41 孙悟空son_ku_kong 阅读(117) 评论(0) 推荐(0)

摘要:1 #include 2 #include 3 int main(){ 4 char s1[100]; 5 gets(s1); 6 puts(s1); 7 printf("字符串长度:%d\n",strlen(s1)); 8 return 0; 9 } 阅读全文

posted @ 2018-06-27 18:40 孙悟空son_ku_kong 阅读(133) 评论(0) 推荐(0)

摘要:1 #include <stdio.h> 2 int main(){ 3 char s1[1]; 4 gets(s1); 5 puts(s1); 6 printf("%d\n",sizeof(s1)); 7 printf("%c\n",s1[1]); 8 return 0; 9 } 阅读全文

posted @ 2018-06-27 18:39 孙悟空son_ku_kong 阅读(119) 评论(0) 推荐(0)

摘要://字符串数组 #include int main(){ char s1[]={"I am a boy"}; char s2[]={"I am a boy\0 and a student"};//遇到\0字符串结束 printf("%s\n",s1); printf("%s\n",s2); return 0; } 阅读全文

posted @ 2018-06-24 10:46 孙悟空son_ku_kong 阅读(116) 评论(0) 推荐(0)

上一页 1 2 3 下一页

导航