随笔分类 - c语言
摘要:#include <stdio.h> main() { int x=10,y=20,t=0; if(x==y) t=x;x=y;y=t; printf("%d %d",x,y); int n=0; while(n++<=1) printf("%d\t",n); printf("%d\n",n); /
阅读全文
摘要:#include <stdio.h> //每找到一个重复的元素,则最末尾前移一位,去重范围缩小一位 //找到重复元素后,此时数组下标之后的元素向前移一位 //程序后,数组中最右边的值是原数组最右边的值 main() { //int a[]={1,1,1,1,2,2,2,2,2,3,4,5,5,6,7
阅读全文
摘要:#include <stdio.h> main() { int a[8][8],i,j; for(i=0;i<8;i++) { a[i][0]=1; a[i][i]=1;} for(i=2;i<8;i++) for(j=1;j<i;j++) a[i][j]=a[i-1][j-1]+a[i-1][j]
阅读全文
摘要:#include <stdio.h> //为小学一年级学生随机出10道题,加法或减法随机出现,保证涉及到的数在0-9之间,结果不能出现负数 //程序运行输入结果后提示对或错,最后并统计做对了几道题,及最后得分(每题10分计算) #include <math.h> #include <stdlib.h
阅读全文
摘要:#include <stdio.h> main() { char s[]="012xy\08s34f4w2"; //ascii码0对应的字符为空字符 //本来\08可以理解为1个字符,但8不是8进制数,斜线只能转义0 //当循环到\0时,循环条件不成立,则退出循环 int i,n=0; for(i=
阅读全文
摘要:#include <stdio.h> #include <string.h> main() { char a[10]="abc",b[10]="012",c[10]="xyz"; strcpy(a+1,b+2);//b+2对应的字符2\0,结果bc改为2\0 ,所以a结果为a2 puts(strca
阅读全文
摘要:#include <stdio.h> #include <string.h> main() { char ab[100]="asdfasd",ac[100]; printf("%d %d\n",ab,ac); //ac=ab 由于ab,ac分别为两个数组的起始地址,所以该句有语法问题 //字符数组相
阅读全文
摘要:#include <stdio.h> #include <math.h> //三角函数的参数为弧度,是角度必须转化为弧度 //3.14=180,1度=3.14/180,转化方法:(3.14/180)*角度值 main() { float a,b,c; c=30; printf("%f",sin(c)
阅读全文
摘要:#include <stdio.h> main() { int a,b,c; for(a=1;a<110;a++) printf("%d ",rand()%10) ; getchar(); } 第一次运行: 第二次运行: 结果相同 一般srand和rand配合使用产生伪随机数序列。rand函数在产生
阅读全文
摘要:#include <stdio.h> //为小学一年级学生随机出10道题,加法或减法随机出现,保证涉及到的数在0-9之间,结果不能出现负数 //程序运行输入结果后提示对或错,最后并统计做对了几道题,及最后得分(每题10分计算) #include <math.h> main() { int i,a,b
阅读全文
摘要:#include <stdio.h> main() { int a,b,c,i; for(a=1;a<=9;a++) for(b=0;b<=9;b++) for(c=0;c<=9;c++) if(a*a*a+b*b*b+c*c*c==a*100+b*10+c) printf("%d ",a*100+
阅读全文
摘要:CPU的数据处理能力 CPU是计算机的核心,决定了计算机的数据处理能力和寻址能力,也即决定了计算机的性能。CPU一次(一个时钟内)能处理的数据的大小由寄存器的位数和数据总线的宽度(也即有多少根数据总线)决定,我们通常所说的多少位的CPU,除了可以理解为寄存器的位数,也可以理解数据总线的宽度,通常情况
阅读全文
摘要:在C语言中,指针变量的值就是一个内存地址,&运算符的作用也是取变量的内存地址,请看下面的代码: #include <stdio.h> #include <stdlib.h> int a = 1, b = 255; int main(){ int *pa = &a; printf("pa = %#X,
阅读全文
摘要:有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约简;若不是则执行第二步。 //第二
阅读全文