随笔分类 -  C语言学习

C语言学习
摘要:#include <stdio.h> #include <string.h> #include <stdlib.h> typedef struct stu{ char num[6];char name[10]; struct stu *next; }List; int main(int argc, 阅读全文
posted @ 2021-01-10 10:15 yanglike111
摘要:#include <stdio.h> #include <stdlib.h> typedef struct node {int x; struct node *next; }NODE; NODE *padd(NODE *pa) { NODE *p1,*p2,*p; p1=p2=pa; while(p 阅读全文
posted @ 2020-11-10 09:02 yanglike111
摘要://写一函数判断并输出任何一个大偶数(>=6)都可以写成两个质数之和 , //我们测试输出6-100之间的偶数是否能写成两个质数之和 #include <stdio.h> #include <math.h> int isprime(int n)//判断是否质数 { int i,k=sqrt(n); 阅读全文
posted @ 2020-11-01 23:50 yanglike111
摘要://下面函数检查给定的字符串s是否满足下列两个条件: //1. 字符串s中左括号"("的个数与右括号")"的个数相同。 //2. 从字符串首字符起顺序检查 s 中的字符的过程中,遇到的右括号")"的个数在任何时候均不超过所遇到的左括号"("数。 //若字符串同时满足上述条件,则函数返回非0 值,否则 阅读全文
posted @ 2020-11-01 23:23 yanglike111
摘要://给定程序,函数fun的功能是:将自然数1-10以及它们的平方根写到名为myfile3.txt的文本文件中, //然后再顺序读出显示在屏幕上。 #include <stdio.h> #include<math.h> //包含数学头文件 int fun(char *fname) { FILE *fp 阅读全文
posted @ 2020-11-01 22:55 yanglike111
摘要:#include <stdio.h> int main() { unsigned int a=6; int b=-20; (a+b>6)?puts("sum>6"):puts("sum<=6"); }//运行结果: sum>6 #include <stdio.h> int main() { int 阅读全文
posted @ 2020-09-23 14:45 yanglike111
摘要:#include <stdio.h> int main() { char s1[]="I love China"; char s2[]="I love"; char *str1=s1,*str2=s2; int answer=0; while(!(answer=*str1-*str2)&& *str 阅读全文
posted @ 2020-09-23 14:25 yanglike111
摘要:#include <stdio.h> int main() { int a[]={89,88,76,70,68,58}; int x=70,mid,pos=-1,find=0,low=0,high=5; while(!find && low<=high){ mid=(low+high)/2; if( 阅读全文
posted @ 2020-09-23 14:13 yanglike111
摘要://下面程序的功能是把一个文件的内容拷贝到另一个文件,如果拷贝成功,则提示 //"File Copy Success!"。 #include <stdio.h> int main() { FILE *fpSrc;//源文件 FILE *fpDes;//目标文件 int ch; if((fpSrc=f 阅读全文
posted @ 2020-09-23 10:54 yanglike111
摘要://下列给定程序中函数f的功能是:根据整型形参(x,t),计算公式前几项的值。 //例如,若x=2,n=10,则输出为:sin(2)=0.909347 #include <stdio.h> double f(int x,int n) { int i,j; long double t,xt; int 阅读全文
posted @ 2020-09-23 10:40 yanglike111
摘要:/*下面程序的功能是:调用Sort()排序函数,通过传递相应参数用选择法按升序(或降序) 对数组中的数进行排序。假设数组中存储数据为{88,67,78,56,90},若升序排序则结果为: {56,67,78,88,90},若降序排序则结果为 {90,88,78,67,56}。 */ #include 阅读全文
posted @ 2020-09-23 09:06 yanglike111
摘要://2020年湖南对口计算机35题。下面程序中定义了三个函数,其功能分别是添加链表结点,显示链表结点与删除链表结点。 //如果添加的链表结点数据为“11,22,33,44,55”,则显示链表为“11->22->33->44->55->End”。如果删除数据为33的结点, //则显示链表为 “11-> 阅读全文
posted @ 2020-09-22 14:30 yanglike111
摘要:#include <stdio.h> int main() { char str[]="hello world"; char *p=str; *(p+5)=0; printf("str=%s\n",str); return 0; } 运行结果:str=hello #include <stdio.h> 阅读全文
posted @ 2020-07-17 09:56 yanglike111
摘要:#include <stdio.h> int main() { int num1=-10; unsigned int num2=10; if(num1>num2) printf("AAA\n"); else printf("BBB\n"); return 0; } 运行结果:AAA 阅读全文
posted @ 2020-07-17 09:48 yanglike111
摘要:#include <stdio.h> #define ROW 2 #define COL 3 int main() { int array[ROW][COL]={{10,20,30},{40,50,60}}; int *p=array[1]; int i=0,j=0; *p=100; *(++p)= 阅读全文
posted @ 2020-07-17 09:43 yanglike111
摘要:#include <stdio.h> int main() { int array[]={11,12,13,14,15}; int *p=array+2; int i=0; *p=100; *(++p)=200; *(p++)=300; for(;i<5;i++) printf("%4d",arra 阅读全文
posted @ 2020-07-17 09:34 yanglike111
摘要:#include <stdio.h> int main() { int array[3][2]={{11,12},{13,14},{15,16}}; int (*p)[2]=NULL; int i=0,j=0; p=array; p[1][0]=10; p[1][1]=20; for(;i<3;i+ 阅读全文
posted @ 2020-07-17 09:30 yanglike111
摘要:/*合并两个有序链表,将两个升序链表合并为一个新的升序链表并返回。 新链表是通过拼接给定的两个链表的所有节点组成的。 例如:输入 1->2->4,1->3->4->5,输出:1->1->2->3->4->4->5 */ #include <stdio.h> #include <stdlib.h> # 阅读全文
posted @ 2020-06-28 10:00 yanglike111
摘要:#include<stdio.h> #include<string.h> int main() { char s[81]; int i,n,m; gets(s); m=strlen(s); while(s[m-1]==32)m--; s[m]=0; i=0; while(s[i]==32)i++; 阅读全文
posted @ 2020-06-27 21:57 yanglike111
摘要:#include<stdio.h> int main() { int sum,n,c;//sum代表喝到的总饮料瓶数,c代表当前的瓶盖数 scanf("%d",&n); sum=n;c=n; while(c>=3) { n=c/3; sum=sum+n; c=n+c%3; } printf("%d" 阅读全文
posted @ 2020-06-27 21:09 yanglike111