轻风逐海浪吧 关注:42贴子:2,558
  • 4回复贴,共1

C程序设计 第四版 谭浩强

只看楼主收藏回复



IP属地:山东1楼2013-04-07 09:55回复
    第5章 习题5
    #include <stdio.h>
    #include <math.h>
    int main()
    {
    int s,a,n,i=1,j,sp=0,k;
    printf("n=");
    scanf("%d",&n);
    printf("a=");
    scanf("%d",&a);
    s=a;
    k=n;
    while(i<n)
    {
    for(j=k-1;j>=0;j--) sp=sp+a*pow(10,j);
    s=s+sp;
    sp=0;
    i=i+1;
    k=k-1;
    }
    printf("s=%d\n",s);
    return 0;
    }


    IP属地:山东2楼2013-04-07 09:56
    回复
      2025-06-09 14:15:57
      广告
      快速排序
      void qsort(int s[], int l, int r) {
      int i, j, x;
      if (l < r) {
      i = l;j = r;x = s[i];
      while (i < j) {
      while(i < j && s[j] > x) j--;
      if(i < j) s[i++] = s[j];
      while(i < j && s[i] < x) i++;
      if(i < j) s[j--] = s[i];
      }
      s[i] = x;
      qsort(s, l, i-1);
      qsort(s, i+1, r);
      }
      }


      IP属地:山东4楼2013-04-21 01:29
      回复
        第六章 第9题
        #include<stdio.h>
        #define t 8
        void cop(int a[15],int b,int c,int d)
        {
        int l,r,n,m;
        l=b; r=c; n=d;
        m=(l+r)/2;
        if (a[m]==n) printf("%d",m);
        else if (a[m]>n) cop(a,m,r,n);
        else cop(a,0,m,n);
        }
        void main()
        {
        int a[15]={15,14,13,12,11,10,9,8,7,6,5,4,3,2,1};
        cop(a,0,15,t);
        }


        IP属地:山东5楼2013-05-02 10:10
        回复
          第七章 习题1
          #include<stdio.h>
          int gcd(int x,int y)
          {
          if(x<y) gcd(y,x);
          if(x%y!=0) gcd(y,x%y);
          else return y;
          }
          int lcm(int x,int y)
          {
          int a,b;
          a=gcd(x,y);
          b=x*y/a;
          return b;
          }
          int main()
          {
          int x,y;
          scanf("%d%d",&x,&y);
          printf("gcd:%d\n",gcd(x,y));
          printf("lcm:%d\n",lcm(x,y));
          return 0;
          }


          IP属地:山东6楼2013-05-10 00:21
          回复