随笔分类 - c语言
摘要:#include <stdio.h> //程序功能: 判断输入字符串是不是手机号 //【1】写最少的数 #include <string.h> main() { char zf[【1】],ch; int a,【2】,c; 【3】; c=【4】; if(【5】 || 【6】) b=1; for(a=0
阅读全文
摘要:#include <stdio.h> //键盘输入任意整数,判断其是否为质数 int pdzs(int n) { int a; for(a=2;a<n;a++) if(n%a==0) 【1】; 【2】; } main() { int a; scanf("%d",&a); if(【3】) printf
阅读全文
摘要:#include <stdio.h> //<<九章算术>>更相减损法: 可以用来求两个数的最大公约数,即“可半者半之,不可半者,副置分母、子之数,以少减多,更相减损,求其等也。 //以等数约之。 ///第一步:任意给定两个正整数;判断它们是否都是偶数。若是,则用2约简;若不是则执行第二步。 //第二
阅读全文
摘要:#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> int gys(int m,int n) { int i,k; k=【1】?m:n; for(i=k;i>=1;i--) { if(【1】) { return 【1】; break; } } } main() { int m,n,i,k; sc
阅读全文
摘要://求最大公约数 #include <stdio.h> main() { int m,n,i,k; scanf("%d,%d",【1】); k=【2】?m:n; for(i=k;i>=1;i--) { if(【3】) { printf("最大公约数为%d\n",【4】); break; } } ge
阅读全文
摘要:#include <stdio.h> //计算1到5的阶乘和,并将结果保存到变量s中 main() { int a,s=【1】,b=【2】; for(a=1;a<=【3】;a++) { b=b*a; s【4】=【5】; } printf("1-5阶乘的和为:%d",s); getchar(); }
阅读全文
摘要:#include <stdio.h> //执行程序段后,变量s的值为() main() { int a=10,s=0; do { s=s+a; a++; } while(a<1); getchar(); } #include <stdio.h> //执行程序段后,变量s的值为(10) main()
阅读全文
摘要:#include <stdio.h> //求s=1+2+3+4+...+100 main() { int a=101,【1】; while(【2】,a>0) s【3】=【4】; printf("s=%d",s); getchar(); } #include <stdio.h> //求s=1+2+3+
阅读全文
摘要:#include <stdio.h> //执行下列程序段后,y的值是(),x的值是(), m的值是(),n的值是() main() { int x,y,z,m,n; m=10;n=5; x=(--m==n++)?--m:++n; y=m++; getchar(); } #include <stdio
阅读全文
摘要:#include <stdio.h> //求两个数中的最大值 int max(int a,int b) { return 【1】; } main() { int a,b; scanf("%d%d",【2】); printf("max=%d",【3】); getchar(); } #include <
阅读全文
摘要:#include <stdio.h> //求任意整数的阶乘 //如果输入3则输出3!=6 main() { int n,a,c=1; scanf("%d",&n); for(a=1;【1】;a++) c=【2】; printf("%d!=%d",【3】); getchar(); } #include
阅读全文
摘要:#include <stdio.h> //找出100-999间所有的Armstrong数 //Armstrong数:指这个3位数各位上数字的立方和等于自身 //371=3*3*3+7*7*7+1*1*1 main() { int i,a,b,c; for(i=100;i<=999;i++) { a=
阅读全文
摘要:#include <stdio.h> //求出a中各相邻两个元素的和,并将这些和存放在数组b中 //按每行3个元素的形式输出。例如:b[1]=a[1]+a[0],....,b[9]=a[9]+a[8] main() { int a[10],b[10],i; printf("\nInput 10 nu
阅读全文
摘要:#include <stdio.h> //输入一行英文,输出单词个数 #include <string.h> main() { char zf[101]; int a,b,【1】; 【1】; a=【1】; for(b=0;【1】;b++) if(zf[b]==【1】) c++; c=【1】; pri
阅读全文
摘要:#include <stdio.h> //输入5个1-9之间的整数,输出其中的最大值和最小值 main() { int a[5],i,j,temp,【1】; for(i=0;i<5;i++) scanf("%d",&a[i]); for(i=0;i<4;i++) for(j=【1】;j<5;j++)
阅读全文
摘要:#include <stdio.h> //从键盘输入一个年份和月份,输出该月的天数 main() { int year,month; scanf("【1】",&year,&month); switch(month) { case 1: case 3: case 5: case 7: case 8:
阅读全文
摘要:#include <stdio.h> //调用函数f,从字符串中删除所有的数字字符 asdf32asdfadsfds\0 数组 #include <string.h> void f(char *s) { int i=0; while(【1】) { if(s[i]>='0' && s[i]<='9')
阅读全文
摘要:#include <stdio.h> //调用函数计算代数多项式1.1+2.2*x+3.3*x*x+4.4*x*x*x+5.5*x*x*x*x //当x=1.7时的值 float f(float,float*,int) ; main() { float b[5]={1.1,2.2,3.3,4.4,5
阅读全文
摘要:#include <stdio.h> //程序功能:调用函数f,将一个整数首尾倒置 //如程序输入12345,则输出54321 // 如程序输入-12345,则输出-54321 #include <math.h> int f(int n) { int m,y=0;m=abs(n); while(m!
阅读全文