
笔记
Final'
HTML ‖ CSS ‖ JavaScript ‖ Vue ‖ React
展开
-
从文件A里读出数据写进文件B
#include<stdio.h>#include<stdlib.h>main(){ FILE *fpa,*fpb; fpa=fopen("a.dat","r"); fpb=fopen("b.dat","w"); if(fpa&&fpb==NULL) { printf("error!"); exit(0); } while(!feof(fpa)) //当fpa指针没到文件尾进行循环 fputc(fgetc(fpa),fpb); //原创 2020-06-19 23:45:37 · 565 阅读 · 0 评论 -
在单链表中插入节点
#include <stdio.h>#include <stdlib.h>struct yo { int data; struct yo *next;};int main() { struct yo *head,*p,*q,*s,*r; p=(struct yo*)malloc(sizeof(struct yo)); p->data=1; head=p; q=(struct yo*)malloc(sizeof(struct yo)); q->原创 2020-06-13 14:02:34 · 1674 阅读 · 0 评论 -
建立单链表,遍历并求其平均数
#include <stdio.h>#include <stdlib.h>//尾插方建立单链表 struct yo{ int data; struct yo *next;};int main(){ struct yo *head,*p,*q,*s; p=(struct yo*)malloc(sizeof(struct yo)); p->data=10; head=p; q=(struct yo*)malloc(sizeof(struct yo));原创 2020-06-12 17:10:00 · 1074 阅读 · 0 评论 -
输入字符,在字符串内查找有无此字符。若有输出此字符第一次出现的位置
include<stdio.h>char* search(char *str,char c) { char *p=str; while(*p!='\0') { if(*p==c) { return p; } p++; } return NULL; } int main() { char ch,*pc=NULL,*string="This a test of search string"; int position原创 2020-06-04 23:28:20 · 2111 阅读 · 1 评论 -
数组元素之和
#include<stdio.h>int sum(int *p,int); //函数声明int main(){ int q[]={10,20,30,40}; int s; s=sum(q,sizeof(q)/sizeof(q[0])); //将数组q和数组长度送入函数 printf("sum=%d\n",s); }int sum(int *p,int length) { int total=0; for(int i=原创 2020-06-02 18:37:40 · 1026 阅读 · 0 评论 -
输入三个字符串,输出最大的
#include<stdio.h>#include<string.h>int main(void){int i;char a[3][99]; char max[10]; for(i=0;i<3;i++){ gets(a[i]); } strcpy(max,a[0]); if(strcmp(max,a[1])<0) strcpy(max,a[1]); if(strcmp(max,a[2])<0)原创 2020-06-02 16:45:20 · 7355 阅读 · 1 评论 -
输入一个单词 将其逆序输出
#include <stdio.h> //int main(){int i,k, temp; char str[99]; printf("input a string: "); //输入字符串i=0;while ((str[i] =getchar() )!='\t') i++; str[i] ='\0'; //在字符串后一位+\0 表明这是个字符串 k=i-1; //k对应数组下标 0-n for(i=0;i<k;i++) //{ tem原创 2020-05-30 17:46:24 · 884 阅读 · 0 评论 -
求二维数组里第一个出现的负数
#include<stdio.h>int main(){ int a[5][7]={1,2,3,4,5,-1,216,-3,-19,198,156,-36,-8,95,71}; for (int i=0;i<5;i++) { for (int j=0;j<7;j++) if (a[i][j]<0) printf("%d\n",a[i][j]); break; }原创 2020-05-26 17:10:41 · 1842 阅读 · 0 评论 -
指向数组的指针跟指向变量的指针的关系
#include<stdio.h> int main(){int a1=123,a2=234,a3=345,i;int *p1,*p2,*p3;int as[3]={1,2,3},*ps;p1=&a1; //p1指向了a1的地址 1000p2=p1+1; //p2指向了a1的下个地址 1004p3=p2+1; //同p2 1008 printf("p1=%p\np2=%p\np3=%p\n",p1,p2,p3); printf("a1=原创 2020-05-22 19:32:28 · 179 阅读 · 0 评论 -
用指针求出数组里最大最小值
#include<stdio.h> void daxiao(int a[],int length,int *min,int *max); //函数声明int main(){ int min,max; //定义两个变量 max min int a[]={19,38,50,3,11,25,69,79,53}; //定义一个数组给出初值 daxiao(a,sizeof(a)/sizeof(a[0]),&min,&am原创 2020-05-21 16:39:28 · 5208 阅读 · 0 评论 -
指针完成变量交换
#include<stdio.h> void swap(int *pa,int *pb) //*pa,*pb代表变量a,b的地址,{ int t; t=*pa; //让a的地址赋给t *pa=*pb; //把b的地址给a *pb=t; //最后把t里面原a的地址给b 完成交换 }int main(){ int a,b原创 2020-05-20 23:12:06 · 326 阅读 · 0 评论 -
函数实现选择排序
#include<stdio.h> int search(int a[] ,int length) //函数定义{ int max=0; //令max=a[0] for(int i=1;i<length;i++){ // i=a[1],i<10,i++ if (a[i]>a[max]) // max=i; //就让a[i]=max; }return max;原创 2020-05-19 18:04:11 · 2298 阅读 · 0 评论