随笔分类 - (草稿)编程应用代码
2xtree
摘要:#include<stdio.h>typedef int ElemType;typedef struct node //定义二叉树结点结构{ ElemType data; struct node *lchild; struct node *rchild;}BTNode;typedef struct //1.定义双亲结构储存类型{ ElemType data; int parent; //指向双亲的位置}ptree[MaxSize];typedef struct node ...
阅读全文
求方程 的根,用三个函数分别求当b2-4ac大于0、等于0、和小于0时的根,并输出结果。从主函数输入a、b、c的值。
摘要:View Code #include<stdio.h>#include<math.h>void yishigen(float m,float n,float k) { float x1,x2; x1=(-n+(float)sqrt(k))/(2*m); x2=(n-(float)sqrt(k))/(2*m); if(x1==x2) printf("=%.3f\n",x1); else printf("two shigen is x1=%.3f and x2=%.3f\n",x1,x2); } void denggen(floa..
阅读全文
求两个整数的最大公约数和最小公倍数
摘要:一、改正下列程序中的编译错误1.写两个函数,分别求两个整数的最大公约数和最小公倍数,用主函数调用这两个函数,并输出结果两个整数由键盘输入。 maxyueshu(m,n); { int i=1,t; for(;i<=m&&i<=n;i++) {if(m%i!=0&&n%i=0) t} return(t); } minbeishu(m,n) {int j; if(m>=n) j=m; else n; for(;!(j%m=!0&&j%n=!0);j++); return j; } main() {int a,b,max,min; p
阅读全文
2.已知int a[10]={1,7,8,18,23,24,59,62,99},删去数组中与3成倍的数。
摘要:View Code #include<stdio.h>void main(){ int a[10]={1,7,8,18,23,24,59,62,99,0},i,j=10,k; for(i=0;i<j;i++) { if(a[i]%3==0) { for(k=i;k<j;k++) a[k]=a[k+1]; j--; } } printf("{"); for(i=0;i<j;i++) printf("%5d",a[i]); printf("}");}
阅读全文
各位数之和
摘要:View Code #include<stdio.h>#include<string.h>#define max 100int func(char x[]){ int h,a,xlen=strlen(x); a=xlen-1; for(h=0;a>=0;a--) { h=h+x[a]-'0';//x[a]不加‘’ } return h;}void main(){ char x[max]; while(scanf("%s",x)!=EOF) { printf("%d\n",func(x)); }}
阅读全文
看是否是回文
摘要:View Code #include<stdio.h>#include<string.h>#define MAX 100int func(char s[]){ int flag=1; int i,j,slen=strlen(s); for(i=0,j=slen-1;i<j;i++,j--) if(s[i]!=s[j]) { flag=0; break; } return flag;}void main(){ char s[MAX]; while(scanf("%s"...
阅读全文
求数的各位数的和
摘要:View Code #include<stdio.h>int func(__int64 x){ int h,a; for(h=0;x>0;x=x/10) { a=x%10; h+=a; } return h;}void main(){ __int64 x; while(1) { scanf("%I64d",&x); printf("%d\n",(int)func(x)); }}
阅读全文
求素数
摘要:View Code #include<stdio.h>#include<math.h>int prime(int x){ int i; for(i=2;i<=(int)sqrt(x);i++) if(x%i==0) return 0; return 1;}void main(){ int a,b; while(1) { scanf("%d",&a); for(b=2;b<=a;b++) if(prime(b)==1) printf("%d\t",b); }}
阅读全文
/*-+
摘要:View Code #include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>#define MAX 80 #define jwcc 50void NiZhi(int *ShuZu,int len) { int i,t; for(i=0;i<=len/2-1;i++) { t=ShuZu[i]; ShuZu[i]=ShuZu[len-i-1]; ShuZu[len-i-1]=t; ...
阅读全文
多字节的+-*
摘要:View Code #include <stdio.h>#include <stdlib.h>#include <string.h>#define MAX 80 #define jwcc 50void NiZhi(int *ShuZu,int len) { int i,t; for(i=0;i<=len/2;i++) { t=ShuZu[i]; ShuZu[i]=ShuZu[len-i-1]; ShuZu[len-i-1]=t; } } void Zh...
阅读全文
+&-
摘要:View Code #include <stdio.h>#include <stdlib.h>#include <string.h>int tidy(char *a,char *b) { int i,la = strlen(a),lb = strlen(b); if(la < lb) { for(i = 0;i < la;i++) a[lb - i - 1] = a[la - i - 1]; for(i = 0;i < lb - la;i++) a[i] = '0'; a[lb] = '\0'; la = l
阅读全文
一个C语言的计算器源代码
摘要:View Code #include <dos.h> /*DOS接口函数*/#include <math.h> /*数学函数的定义*/#include <conio.h> /*屏幕操作函数*/#include <stdio.h> /*I/O函数*/ #include <stdlib.h> /*库函数*/#include <stdarg.h> /*变量长度参数表*/#include <graphics.h> /*图形函数*/#include <string.h> /*字符串函数*/#include &
阅读全文
符号转数字
摘要:#include<stdio.h>int ctoi(char *p){ int sum=0; while(*p) { sum*=10; sum+=*p-'0'; p++;} return sum;}int main(){ char str[5]; int x; while(scanf("%s",str)!=EOF) { x=ctoi(str); printf("x=%d\n",x); x=x*10; printf("%d\n",x);} return 0;}
阅读全文
strlen
摘要:#include <string.h>#include<stdio.h>int main(void){char *s="Golden Global View";printf("%s has %d chars",s,strlen(s));getchar();return 0;}strlen
阅读全文
数字转符号
摘要:c#include<stdio.h>#include<string.h>#include<math.h>#define NUM 10000int weishu(__int64 p){__int64 n=0,i=1;__int64 m=1;if(p==0)return 0;while(n>10||n<1){ n=p/i; i*=10; m++;}return m-1;}void main(){__int64 a,b,n,q=0,i=0;char str[NUM];scanf("%I64d",&a);n=weishu(a)
阅读全文
浙公网安备 33010602011771号