随笔分类 - c语言例子
摘要:有4个圆塔,圆心分别为(2,2)、(-2,2)、(-2,-2)、(2,-2),圆半径为1。这4个塔的高度为10m,塔以外无建筑物。今输入任一点的坐标,求该点的建筑高度(塔外的高度为0) #include <stdio.h> //四个圆心坐标:(2,2) (-2,-2) (2,-2) (-2,2) /
阅读全文
摘要:#include <stdio.h> #include <math.h> main() { int a,b,c,d; for(a=-9;a<=9;a++) { for(b=1;b<=19-abs(a);b++) printf(" "); for(c=0;c<2*abs(a)+1;c++) print
阅读全文
摘要:#include <stdio.h> //数组整体赋值使用scanf()用数组名只能给第一个赋值 main() { int a[4],b; scanf("%d",a); for(b=0;b<4;b++) printf("%d ",a[b]); getchar(); } 搜索 复制
阅读全文
摘要:#include <stdio.h> #include <string.h> void lianjie(char a[],char b[],char c[]) { int i,j,len1=strlen(a),len2=strlen(b); for(i=0;i<len1;i++) c[i]=a[i]
阅读全文
摘要:#include <stdio.h> //求最大公约数:辗转相除法:辗转相除法是求两个自然数的最大公约数的一种方法,也叫欧几里德算法。 //319 377:319%377=319 377%319=58 319%58=29 58%29=0 29为最大公约数 int gys(int a,int b) {
阅读全文
摘要:#include <stdio.h> //求最大公约数:辗转相除法:辗转相除法是求两个自然数的最大公约数的一种方法,也叫欧几里德算法。 //319 377:319%377=319 377%319=58 319%58=29 58%29=0 29为最大公约数 main() { int a=319,b=3
阅读全文
摘要:#include <stdio.h> //<<九章算术>>更相减损法: 可以用来求两个数的最大公约数,即“可半者半之,不可半者,副置分母、子之数,以少减多,更相减损,求其等也。 //以等数约之。 ///第一步:任意给定两个正整数;判断它们是否都是偶数。若是,则用2约简;若不是则执行第二步。 //第二
阅读全文
摘要:#include <stdio.h> //<<九章算术>>更相减损法: 可以用来求两个数的最大公约数,即“可半者半之,不可半者,副置分母、子之数,以少减多,更相减损,求其等也。 //以等数约之。 ///第一步:任意给定两个正整数;判断它们是否都是偶数。若是,则用2约简;若不是则执行第二步。 //第二
阅读全文
摘要:#include <stdio.h> fun(char x) { char y; y=x-4; return y; } main() { printf("%d",sizeof(fun(97))); printf("\n%d",fun(97)); getchar(); }
阅读全文
摘要:#include <stdio.h> void f(int n); void g(int n) { f(n); } main() { void f(int n); f(5); getchar(); } void f(int n) { printf("%d",n); } 如果第二行的函数声明放在g函数
阅读全文
摘要:#include <stdio.h> //数组与指针 main() { int x[8]={8,7,6,5,0,0},*s; s=x+3; printf("%d %d %d %d %d %d",s[0],s[1],s[2],s[3],s[4],s[5]); getchar(); }
阅读全文
摘要:#include <stdio.h> int d=1; fun(int q) { int d=5; d+=q++; printf("%d ",d); } main() { int a=3; fun(a); d+=a++; printf("%d\n",d); getchar(); }
阅读全文
摘要:#include <stdio.h> main() { int days,sum=1; scanf("%d",&days); while(--days) { sum=(sum+1)*2; } printf("%d",sum); getchar(); } #include <stdio.h> int
阅读全文
摘要:#include <stdio.h> #include <math.h> #define N 10 //一个球从100米高度自由落下,每次落地后返回高度的一半,再落下,再反弹。求它在第10次落地时,共经过多少米? main() { float s=200,b=100,c; int a; for(a=
阅读全文
摘要:#include <stdio.h> int hws(int a) { int b=0,c=a; while(a) { b=b*10+a%10; a=a/10; } if(c==b) return 1; else return 0; } main() { int a,b; for(a=100;a<=
阅读全文
摘要:#include <stdio.h> main() { int a; for(a=1;a<100;a++) if(a%3==2 && a%5==4) { printf("%d",a); break; } getchar(); }
阅读全文
摘要:#include <stdio.h> main() { int a,b=0,c; scanf("%d",&a); while(a) { b=b*10+a%10; a=a/10; } printf("%d",b); getchar(); } #include <stdio.h> void fx(int
阅读全文
摘要:#include <stdio.h> void zys(int a) { int i; printf("%d=",a); for(i=2;i<=a;i++) { while(a%i==0) { printf("%d",i); a/=i; if(a!=1) printf("*"); } } } mai
阅读全文
摘要:#include <stdio.h> //求1/2,2/3,3/5,5/8,8/13,13/21,21/34...前20项和 main() { int a,c=1; double sum=0,b=1.0,d,e,f=1,g=2; for(a=1;a<=20;a++) { d=f/g; sum=sum
阅读全文
摘要:字符:1.char ab='A'; ab='\101'; ab='\x41' 只有一个字符字符数组1.字符串结束标志'\0'2.n个字符串,占用n+1个字节3.字符串输出标志符:%s初始化:2.char ab[]="asdfasdf"; char ac[20]={'a','b','c'};3.字符数
阅读全文

浙公网安备 33010602011771号