随笔分类 - c语言例子
摘要:#include <stdio.h> main() { char a[3][10]={"beijing","shanghai","tianjin"},*pa=a[0]; printf("%s\n",*(a+1)); printf("%s\n",a+1); printf("%s\n",*a+1); p
阅读全文
摘要:#include <stdio.h> int sx(int n) { int a; for(a=2;a<n;a++) if(n%a==0) return 0; return 1; } void sxa(int b) { int c=1,a=b; while(c<=5) { a=a+1; if(sx(
阅读全文
摘要:#include <stdio.h> main() { int n,a[10]={0}; scanf("%d",&n); while(n>0&&n<=99) { if(n>0 && n<=10) a[(n-1)/10]++; else a[n/10]++; scanf("%d",&n); } for
阅读全文
摘要:#include <stdio.h> main() { int i,n,s; s=0; scanf("%d",&n); for(i=1;i<n;i++) if(n%i==0) s=s+i; if(s==n) printf("%d是完数",n); else printf("%d不是完数",n); ge
阅读全文
摘要:#include <stdio.h> int zs(int n) { int a; for(a=2;a<n;a++) if(n%a==0) return 0; return 1; } main() { int a,b,c=0; scanf("%d",&a); for(b=a-1;b>=2;b--)
阅读全文
摘要:#include <stdio.h> #include <string.h> main() { char zf[100],ch; int a,b=0,c; gets(zf); c=strlen(zf); if(c!=11 || zf[0]!='1') b=1; for(a=0;a<11;a++) {
阅读全文
摘要:#include <stdio.h> float fh(int n) { if(n==1) return 1; else return 1/(n-1+1/fh(n-1)); } main() { float aa=0; int a,b; for(a=1;fh(a)>=0.001;a++) //pri
阅读全文
摘要:#include <stdio.h> //假设商品销售额为16800(不开票),客户需要开发票,税(0.12)需要开在发票中 //编程计算最后的开票金额 main() { float a=16800,b=0.12,c,d=16800; c=a*b; while(c>=1) { d=d+c; c=c*
阅读全文
摘要:用户输入两个正整数,第一个代表头数,第二个代表脚数,计算鸡和兔的数量,若无解输出Error #include <stdio.h> main() { int a,b,j,t; scanf("%d%d",&a,&b);//头数 脚数 j=(4*a-b)/2;//头数的4倍(鸡的4倍相当于鸡的脚数的2倍,
阅读全文
摘要:#include <stdio.h> /* 身份证号码是由18位数字组成的,他们分别表示: 1、前1、2位数字表示:所在省份的代码。 2、前3、4位数字表示:所在城市的代码。 3、前5、6位数字表示:所在区县的代码。 4、第7~14位数字表示:出生年、月、日,7、8、9、10位是年,11、12位是月
阅读全文
摘要:char a='9'; int b=a-'0'; printf("%d",b); 结果:9
阅读全文
摘要:#include <stdio.h> main() { int n=10,a=1,b=1,c; for(a>0;a<3;a++) for(b>0;b<3;b++) c=n-a; printf("%d %d",a,c); getchar(); }
阅读全文
摘要:#include <stdio.h> //任意鸡兔同笼问题 main() { int a,b,ji,tu,d=0; scanf("%d%d",&a,&b); for(ji=0;ji<=a+b;ji++) { for(tu=0;tu<=a+b;tu++) { if(ji+tu==a && 2*ji+t
阅读全文
摘要:#include <stdio.h> //n个硬币,甲(Rui)乙(Seven)两人轮流取硬币,每次最少取1个,最多取3个 。甲先取,取走最后1个硬币者获胜; //甲乙都能做出最佳选择的情况下,输赢只与硬币数量n有关。编程任意n个硬币,如果甲赢输出"Rui",乙赢输出"Seven" //每个人都想最
阅读全文
摘要:#include <stdio.h> #include <time.h> // time_t数据类型,日历时间头文件 int main(void) { int year,month,day,n,y,r,zhou; time_t current = time(NULL); // 利用time函数获取日
阅读全文
摘要:#include <stdio.h> int gygb(int m,int n,int x) { int a; if(x==0) { for(a=m;a>=1;a--) if(m%a==0 && n%a==0) return a; return a; } else { for(a=m;a<m*n;a
阅读全文
摘要:#include <stdio.h> #include <string.h> struct data {char name[7];int age;} ab[5]={"张三",10,"李四",11,"张五",12,"李六",13,"陈七",14}; //编程将数组中所有姓张的年龄增加1,姓李的增加2,
阅读全文
摘要:#include <stdio.h> struct data {char name[7];int age;} ab[5]={"张三",10,"李四",11,"张五",12,"李六",13,"陈七",14}; //编程将数组中所有姓张的年龄增加1,姓李的增加2,然后输出各个人的姓名与年龄 //中文字符
阅读全文
摘要:#include <stdio.h> #include <time.h> int main () { time_t tt;//typedef long time_t;time_t实际上是long型,从一个时间点(一般是1970年1月1日0时0分0秒)到当前的秒数。 time(&tt); //获取秒数
阅读全文

浙公网安备 33010602011771号