- 博客(35)
- 收藏
- 关注
原创 写入文件信息,读出文件信息(存档)
1.不知道为什么里面没东西,但是文件在#include <stdio.h>#include <stdlib.h>#define N 30typedef struct date{ int year; int month; int day;}DATE;typedef struct student{ long ID; char Name[10]; char Sex; DATE birthday; int s
2022-02-26 21:24:40
250
原创 顺序链表合并
1.#include "common.h"#include "seqlist.h"void merge(SeqList *LA, SeqList *LB, SeqList *LC){ int i,j,k; i=0; j=0; k=0; while(i<=LA->last&&j<=LB->last) if(LA->elem[i]<=LB->elem[j]) {
2022-02-26 19:48:46
265
原创 文件操作存档2
将0-127之间的ASCII字符写入demo.bin二进制文件中,并读取内容显示#include <stdio.h>#include <stdlib.h>int main(){ FILE *fp; char ch; int i; if( (fp = fopen("demo.bin","wb")) == NULL)//以二进制写方式打开文件 { printf("Failure to open demo.bin!\n
2022-02-25 21:28:48
155
原创 文件操作存档
#include <stdio.h>#include <stdlib.h>int main(){ FILE *fp; char ch; if( ( fp = fopen( "demo.txt","w" ) ) == NULL ) { printf("Faliure to open demo.txt!\n"); exit(0); } /*fp = fopen("demo.txt","w");.
2022-02-25 21:06:26
422
原创 结构体指针做函数参数
1.#include <stdio.h>#include <stdlib.h>struct date{ int year; int month; int day;};void Func(struct date *p){ p->year=2000; p->month= 5; p->day = 22;}int main(){ struct date d; d.year = 199
2022-02-22 21:04:00
897
原创 输入,输出二维数组
1.数组void InputArray(int a[][N],int m,int n){ int i,j; for( i=0;i<m;i++) { for( j=0;j<n;j++ ) { scanf("%d",&a[i][j]); } }}void OutputArray(int a[][N],int m,int n){ int i,j; for(
2022-02-21 20:52:47
788
原创 一维数组元素的引用方法
1.#include <stdio.h>#include <stdlib.h>int main(){ int a[5],i; printf("Input five numbers:"); for(i=0;i<5;i++) { scanf("%d",&a[i]); } for( i=0; i<5; i++) { printf("%4d",a[i]); }
2022-02-21 18:07:55
826
原创 自己的复制字符串和计算字符串长度和连接两个字符串
一、strcpy1.void MyStrcpy(char dstStr[],char srcStr[]){ int i=0; while(srcStr[i]!='\0') { dstStr[i]=srcStr[i]; i++; } dstStr[i] = '\0';2.用指针void MYStrcpy(char *dstStr,char *srcStr){ while (*srcStr != '\0')
2022-02-18 13:13:41
523
转载 将国家名字按顺序排序
#include <stdio.h>#include <stdlib.h>#include <string.h>#define MAX_LEN 10#define N 150void SortString(char str[][MAX_LEN],int n){ int i,j; char temp[MAX_LEN]; for(i=0;i<n-1;i++) { for(j=i+1;j<n;j++).
2022-02-18 10:39:51
408
原创 去掉缓冲区中的其他字符
1.do { printf("Input a:"); ret=scanf("%d",&a); if(ret!=1) { while(getchar()!='\n'); } }while(ret!=1);2.去掉空白字符scanf(" ");
2022-02-10 17:58:44
478
原创 升序、降序输出成绩(指针)
#include <stdio.h>#include <stdlib.h>#define N 30int ReadScore(int score[]){ int i = -1; do{ i++; printf("Input score:"); scanf("%d",&score[i]); }while (score[i] >= 0); return i;}void Prin.
2022-02-10 12:06:23
727
原创 计算 函数 f1 的定积分
f1=1+x^2float f1(float x){ return 1+x*x;}float Integralf1(float a,float b){ float s,h; int n = 100,i; s = ( f1(a) + f1(b) )/2; h= ( b-a ) / n; for( i=1;i<n;i++ ) { s + = f1(a+i*h); } return s * h;}y
2022-02-10 11:34:49
571
原创 有关 素数
1.int IsPrime(int x){ int i,flag = 1; int squareRoot = sqrt(x); if(x <= 1) flag = 0; for(i=1;<=squareRoot && flag;i++) { if(x%i==0) flag=0; } return flag;}2.筛法求100以内的所有素数(1
2022-01-28 16:58:12
179
原创 关于查找()
查找学号1.顺序查找int LinSearch(long num[],long x,int n)//顺序查找{ int i; for(i=0;i<n;i++) { if(num[i]==x) { return i; } } return -1;}2.折半查找要先排序!2.1int BinSearch(long num[],long x,int n){
2022-01-28 16:26:34
387
原创 关于排序()
1.交换法排序void DataSort1(int score[],int n)//交换法{ int i,j,temp; for(i=0;i<n-1;i++) { for(j=i+1;j<n;j++) { if(score[j]>scorre[i])//从高到低 { temp=score[i]; score
2022-01-28 15:45:08
90
原创 用 函数 输入并计算平均分等
1.简单求平均#include <stdio.h>#include <stdlib.h>#define N 40int Average(int score[],int n){ int i; int sum=0; for(i=0;i<n;i++) { sum=sum+score[i]; } return n>0?sum/n:-1;}void ReadScore(int score[],in
2022-01-28 15:04:25
1143
原创 显示用户输入的月份的天数
#include <stdio.h>#include <stdlib.h>#define MONTHS 12int main(){ int days[MONTHS]={31,28,31,30,31,30,31,31,30,31,30,31}; int month; do{ printf("Input a month:"); scanf("%d",&month); }while(month<1 |.
2022-01-27 16:48:12
1130
原创 函数名命名规则
1.Linux/UNIX 风格用下划线function_name2.Windows 风格大写字母开头,大小写混排的单词组合FunctionName3.变量名形式“名词”或者“形容词+名词”oldValue 与 newValue等。函数名形式“动词”或者“动词+名词”(动宾词组)GetMax()等。...
2022-01-27 15:59:36
2564
原创 把函数的注释写的好看
/*函数功能:实现xxx功能 函数参数:参数1,表示xx 参数2,表示xx 函数返回值:xxxxx*/返回值类型 函数名(形参表){ ... return 表达式; }eg:/*函数功能:用迭代法计算n! 函数入口参数:整型变量n表示阶乘的阶数 函数返回值:返回n!的值*/long Fact(int n){ int i; long result = 1; for(i=2; i<=n;i.
2022-01-27 15:52:30
296
原创 静态变量与动态变量的阶乘
1.静态变量的阶乘#include <stdio.h>#include <stdlib.h>long Func(int n);int main(){ int i,n; printf("Input n:"); scanf("%d",&n); for(i=1;i<=n;i++) { printf("%d!=%ld\n",i,Func(i)); } return 0;}long Fu
2022-01-27 15:15:43
688
原创 汉诺塔问题
汉诺塔问题(Hanoi塔)#include <stdio.h>#include <stdlib.h>void Move(int n,char a,char b){ printf("Move %d:from %c to %c\n",n,a,b);}void Hanoi(int n,char a,char b,char c){ if(n == 1 ) { Move(n,a,b); } else {
2022-01-26 16:57:03
242
原创 斐波那契数列(递归)
fib(n)= 0 n=01 n=1fib(n-1)+fib(n-2) n>1long Fib(int n){ long f; if( n == 0 ) f = 0; else if( n == 1 ) f = 1; else f = Fib...
2022-01-26 16:01:17
245
原创 递归函数求阶乘
n!=n*(n-1)*(n-2)*(n-3)*...*1n! = 1 n=0,1 n*(n-1) n>=2long Fact(int n){ if(n<0) return -1; else if(n==0||n==1) return 1; else return n*Fact(n-1);}unsigned intunsigned long Fact(u...
2022-01-26 15:58:47
249
原创 求组合数Cmk
Cmk=m!/k!(m-k)!#include <stdio.h>#include <stdlib.h>unsigned long Fact(unsigned int n){ unsigned int i; unsigned long result = 1; for ( i=2;i<=n;i++ ) { result=result*i; } return result;}int main()
2022-01-26 15:21:38
414
原创 用函数求阶乘
迭代。/*函数功能:用迭代法求n! 函数入口参数:整型变量n表示阶乘的阶数 函数返回值:返回n!的值*/long Fact(int n)/*求阶乘的函数*/{ int i; long result = 1; for ( i=2;i<=n;i++ ) { result=result*i; } return result; }...
2022-01-26 12:27:09
1034
原创 循环的小集合
1.a+aa+aaa+aaaa+....+aaa...aa(n个a)term=term*10+a;term 初值为0。#include <stdio.h>#include <stdlib.h>#include <math.h>int main(){ int a; int n; int i; int term; long sum; sum = 0; term = 0; scanf("
2022-01-26 10:53:27
154
原创 【无标题】
1-1/2+1/3-1/4+...直到最后一项小于1e-4。#include <stdio.h>#include <stdlib.h>#include <math.h>int main(){ double sigh,n; double term; double sum; n=1; sum=0.0; sigh=1; do { term=sigh/n; sum
2022-01-25 16:54:40
69
原创 【无标题】
π/2=2/1*2/3*4/3*4/5*6/5*6/7*...求π#include <stdio.h>#include <stdlib.h>int main(){ double term,result = 1.0; int n; for(n = 2;n <= 100;n = n+2) { term = (double)(n*n) / ( (n-1)*(n+1) ); result = result
2022-01-25 16:19:28
147
原创 韩信点兵()
1-5报数最末报1,1-6最末报5,1-7最末报4,1-11最末报10。韩信至少有多少兵。1.#include <stdio.h>#include <stdlib.h>int main(){ int n; for(n=1;;n++) { if(n%5==1&&n%6==5&&n%7==4&&n%11==10) { prin
2022-01-25 15:25:17
209
原创 求和和阶乘的和
一、1+2+3+....+n#include <stdio.h>#include <stdlib.h>int main(){ int i,n,sum=0; scanf("%d",&n); for(i=1;i<=n;i++) { sum=sum+i; } printf("%d",sum); return 0;}二、1+2!+3!+...+n!1.#include <
2022-01-25 12:46:27
94
原创 e=1的阶乘+1/2的阶乘+1/3的阶乘+...+1/n的阶乘,直到最后一项小于1e-5
1和2不知道为什么有时会不一样,明明只是名字变了变。思路两个1.求出阶乘。1/阶乘。求和。2.1/n!=1/(n-1)/n;后一项的阶乘等于前一项除以后一项的标码。#include <stdio.h>#include <stdlib.h>#include<math.h>int main(){printf("1."); double e=1.0,term; int n,count=1; .
2022-01-25 12:34:15
1733
原创 简单的猜数2
1.无限猜数版1.1#include <stdio.h>#include <stdlib.h>#include <time.h>int main(){ int magic; int guess; unsigned int seed; int counter; srand(time(NULL)); counter=0; magic=rand()%100+1; //printf("%d\.
2022-01-25 11:45:06
190
原创 简单的猜数1(使用的函数)
一、函数1.rand()函数2.srand()函数3.time()函数包含在time.h。1.randmagic=rand()%100+1;如果直接这样用答案一直是42。--------------------------------------int i; for(i=0;i<10;i++) { printf("%d\n",rand()%100+1); }这样输出的结果是2.srand输入se..
2022-01-25 11:15:17
1198
原创 循环输入数字并求和
两个方法。1在/*里。2不要注释。#include <stdio.h>#include <stdlib.h>int main(){ /*int num; int sum=0; do{ printf("Input a number:"); scanf("%d",&num); sum=sum+num; printf("sum=%d\n",sum); }while(
2022-01-24 19:45:42
894
原创 阶乘,阶乘的和
输入n并计算1!+2!+3!+...+n!#include <stdio.h>#include <stdlib.h>#include<math.h>int main(){ int i,j,n; long term,sum=0; scanf("%d",&n); for(i=1;i<=n;i++) { term=1; for(j=1;j<=i;j++)
2022-01-24 13:16:36
101
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人