004 C语言基础

//  031.c
#include
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
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
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
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
void main()
{
   int a=6,x;
   x=3>2?2:3>2?a++:6;
   printf("%d",a);
   getch();
}
```

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

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

```
//  039.c
#include
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
int fun(int n)
{
   if(n==0)return 0;
   return fun(n-1)+n;
}
void main()
{
    printf("%d",fun(100));
    getch();
}
```

你可能感兴趣的:(004 C语言基础)