美文网首页
007 C语言基础

007 C语言基础

作者: PYGY | 来源:发表于2017-06-21 18:25 被阅读0次
//  061.c
#include<stdio.h>
void main()
{
    int x,m,i;
    for(x=1;;x++)
    {
      m=x;
      for(i=0;i<9;i++)
         m=m/2-1;
      if(m==1)break;
    }
    printf("%d",x);
    getch();
}
// 062.c
//π/4≈1-1/3+1/5-1/7+…
#include<stdio.h>
void main()
{
    float s=0;
    int i,flag=1;
    for(i=1;i<3000;i+=2)
    {
       s=s+flag*1.0/i;
       flag=-flag;
    }
    printf("%f",4*s);
    getch();
}
//  063.c
//π/4≈1-1/3+1/5-1/7+…
#include<stdio.h>
float fun(int n)
{
   int flag=1;
   if(n==1)return 1.0;
   if(n%2==0)flag=-1;
   else flag=1;
   return fun(n-1)+flag*1.0/(2*n-1);
}
void main()
{
   printf("%f",4*fun(1000));
   getch();
}
//  064.c
#include<stdio.h>
void main()
{
    int f1,f2,i;
    f1=f2=1;
    printf("%4d%4d",f1,f2);
    for(i=1;i<=5;i++)
    {
       f1=f1+f2;
       f2=f1+f2;
       printf("%4d%4d",f1,f2);
    }
    getch();
}
//   065.c
#include<stdio.h>
void main()
{
    char x,y,z;
    for(x='a';x<='c';x++)
      for(y='a';y<='c';y++)
        for(z='a';z<='c';z++)
          if(x!=y&&x!=z&&y!=z&&x!='a'&&x!='c'&&z!='c')
           printf("X--%c\nY--%c\nZ--%c\n",x,y,z);
    getch();
}
//   066.c
#include<stdio.h>
void main()
{
   int i,j;
   for(i=0;i<4;i++)
   {
        for(j=0;j<3-i;j++)printf(" ");
        for(j=0;j<2*i+1;j++)printf("*");
        printf("\n");
   }
   for(i=2;i>=0;i--)
   {
        for(j=0;j<3-i;j++)printf(" ");
        for(j=0;j<2*i+1;j++)printf("*");
        printf("\n");
   }
   getch();
}
//  067.c
#include<stdio.h>
int fun(int i,int j)
{
   if(i==j||j==0)return 1;
   return fun(i-1,j)+fun(i-1,j-1);
}
void main()
{
   int i,j;
   for(i=0;i<10;i++,printf("\n"))
     {
     for(j=0;j<=10-i;j++)printf(" ");
     for(j=0;j<=i;j++)
        {
           printf("%4d",fun(i,j));
        }
      }

   getch();
}
//   068.c
#include<stdio.h>
int fun(int n)
{
   int i,s=0;
   for(i=1;i<n;i++)
     if(n%i==0)s=s+i;
   if(s==n)return 1;
   return 0;
}
void outfun(int n)
{
   int i;
   printf("1");
   for(i=2;i<n;i++)
     if(n%i==0)printf("+%d",i);
}
void main()
{
   int x;
   for(x=1;x<1000;x++)
     if(fun(x)==1){printf("%d=",x);
     outfun(x);
     printf("\n");}
   getch();
}
//   069.c
#include<stdio.h>
void main()
{
   int i,j,k,s=0;
   for(i=1;i<=4;i++)
      for(j=1;j<=4;j++)
         for(k=1;k<=4;k++)
         {
            if(i!=j&&j!=k&&i!=k)s++;
         }
   printf("%d",s);
   getch();
}
//  070.c
#include<stdio.h>
void main()
{
   int x,s=0,t=1;
   scanf("%d",&x);
   while(x)
   {
      s=s+x%10*t;
      t=t*8;
      x=x/10;
   }
   printf("%d",s);
   getch();
}

相关文章

网友评论

      本文标题:007 C语言基础

      本文链接:https://www.haomeiwen.com/subject/nvptcxtx.html