C语言经典例题

一次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) && (a%100!=0)   ) || (a%400==0)    )

   printf("闰年/n");
}

 

找水仙花数.c

main()

{
int g, s, b, x;

for(x=100;x<1000;x++)
{
   g=x%10;
   s=x/10%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 );
   }
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值