计算机等考二级C语言的经典例题
来源:优易学  2011-9-21 17:19:47   【优易学:中国教育考试门户网】   资料下载   IT书店
  一次for循环完成1!+2!+...+10!.c
  main()
  {
  long s=0,n=1;
  int i;
  for(i=1;i<=10;i++)
  {
  n=n*i;
  s=s+n;
  }
  printf("s=%ld\n",s);
  }
  杨辉三角.c
  main()
  {
  int a[10][10], x, y;
  for(x=0;x<10;x++)
  for(y=0;y<10;y++)
  a[x][y]=0;
  for(x=0;x<10;x++)
  a[x][0]=1;
  for(x=1;x<10;x++)
  for(y=1;y<10;y++)
  {
  a[x][y]=a[x-1][y-1]+a[x-1][y];
  if(a[x][y]==1)
  break;
  }
  for(x=0;x<10;x++)
  {
  for(y=0;y<10;y++)
  {
  if(a[x][y]!=0)
  printf("%d",a[x][y]);
  }
  printf("\n");
  }
  }
  连接两字符串.c
  #include "stdio.h"
  main()
  {
  int i,j=0;
  char str1[50], str2[20];
  scanf("%s%s",str1,str2);
  for(i=0;str1[i]!='\0';i++);
  for(;;i++,j++)
  {
  str1[i]=str2[j];
  if(str1[i]=='\0')
  break;
  }
  }
  找闰年.c
  main()
  {
  int a;
  scanf("%d",&a);
  if( ( (a%4==0) && (a0!=0) ) || (a@0==0) )
  printf("闰年\n");
  }
  找水仙花数.c
  main()
  {
  int g, s, b, x;
  for(x=100;x<1000;x++)
  {
  g=x;
  s=x/10;
  b=x/100;
  if( g*g*g + s*s*s + b*b*b == x )
  printf("%d\t",x);
  }
  }
  百钱买百鸡.c
  main()
  {
  int x, y, z;
  for(x=0;x<=20;x++)
  {
  for(y=0;y<=34;y++)
  {
  z = 100 - (x+y) ;
  if ( 5*x + 3*y + z/3 == 100 )
  printf( "\t公鸡%d只\t母鸡%d只\t小鸡%d只\n", x, y, z );
  }
  }
  }

责任编辑:小草

文章搜索:
 相关文章
热点资讯
资讯快报
热门课程培训