004 C语言基础

//  031.c
#include<stdio.h>
int fun(int x)
{
   int a,b,c,d;
   a=x/1000;
   b=x/100%10;
   c=x/10%10;
   d=x%10;
   if(a==d&&b==c)return 1;
   return 0;
}
void main()
{
   int x;

   for(x=1000;x<10000;x++)
   if(fun(x))printf("%5d",x);
   getch();
}
//  032.c
#include<stdio.h>
int fun(unsigned int x)
{
   unsigned a=0,b=x;
   while(x)
   {
       a=a*10+x%10;
       x=x/10;
   }
   if(a==b)return 1;
   return 0;
}
void main()
{
   unsigned int x;
   for(x=10;x<50000;x++)
   {
      if(fun(x))printf("%6u",x);
   }
   getch();
}
//  033.c
#include<stdio.h>
int fun(int x)
{
   if(x<10){printf("%d",x);return ;}

   printf("%d",x%10);fun(x/10);
}
void main()
{
   int x=567;
   fun(x);
   getch();
}
//  034.c
#include<stdio.h>
int fun(int a,int b)
{
   //return a>b?a:b;
   if(a>b)return a;
   else return b;

   if(a>b)return a;
   return b;
}
void main()
{
   int a,b;

   getch();
}
// 035.c
#include<stdio.h>
void main()
{
   int a=6,x;
   x=3>2?2:3>2?a++:6;
   printf("%d",a);
   getch();
}
```

```
//  036.c
#include<stdio.h>
void main()
{
    int s=0,i;
    for(i=0;i<=100;i++)
       s=s+i;
    printf("%d",s);
    getch();
}
```

```
// 037.c
#include<stdio.h>
void main()
{
    int s=0,i;
    i=1;
    while(i<=100)
    {
      s=s+i;
      i++;
    }
    printf("%d",s);
    getch();
}
```
```
// 038.c
#include<stdio.h>
void main()
{
    int s=0,i;
    i=1;
    do
    {
       s=s+i;
       i++;
    }while(i<=100);
    printf("%d",s);
    getch();
}
```

```
//  039.c
#include<stdio.h>
void main()
{
    int s=0,i;
    i=1;
    loop:
      s=s+i;
      i++;
    if(i<=100)goto loop;
    printf("%d",s);
    getch();
}
```

```
//  040.c
#include<stdio.h>
int fun(int n)
{
   if(n==0)return 0;
   return fun(n-1)+n;
}
void main()
{
    printf("%d",fun(100));
    getch();
}
```

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容