随笔分类 - c语言例子
摘要:#include <stdio.h> //http://www.china-audit.com/lhd_4awla5u6mp47ty70kclt55mbv23rb1005bb_1.html //实现输入两个数字,若两数相等,则直接输出两个数字;若不相等,则这两个数中的 //较大者等于这个较大者减去较
阅读全文
摘要:#include <stdio.h> //键盘输入任意整数,判断其是否为质数 int pdzs(int n) { int a; if(n==1) return 0; for(a=2;a<n;a++) if(n%a==0) return 0; return 1; } main() { int a=1,
阅读全文
摘要:#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=【2】;j
阅读全文
摘要:#include <stdio.h> //输入一行英文,输出单词个数 //输入一行字符串,由英语单词和若干空格组成,输出单词个数。(约定第一个单词前和最后一个单词后没有空格,输入最多100个字符) #include <string.h> main() { char zf[101]; int a,b,
阅读全文
摘要:#include <stdio.h> //输人一个5行5列的二维数组,将其按行存储在一个一维数组中并输出。 main() { int a[5][5],b[25],c,d,e=0; for(c=0;c<5;c++) for(d=0;d<5;d++) { scanf("%d",&a[c][d]); b[
阅读全文
摘要:#include <stdio.h> //哥德巴赫猜想是指任一大于2的偶数都可写成两个素数之和,请输入任何一个大于2的偶数,将其分解为两个素数之和并输出, //输出格式如下:如输入8,则输出:8=3+5,有多个结果的只输出一个即可,注意1不是素数,故不能输出8=1+7, //如输入非法则给出提示,本
阅读全文
摘要:#include <stdio.h> //程序功能:将任意字符串转置并输出 #include <【1】> main() { char c[20]; int i=0,j; char ch; 【2】; j=【3】; while(【4】) { ch=c[i]; c[i]=c[j-1]; c[j-1]=ch
阅读全文
摘要:#include <stdio.h> //a b c均为一位整数,求当三位整数abc+cba=1333时的a,b,c的值 main() { int a,b,c; for(a=1;【1】;a++) for(【2】;b<=9;b++) for(【3】;c<=9;c++) if(【4】) printf("
阅读全文
摘要:#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
阅读全文

浙公网安备 33010602011771号