博文

求二次方程的根的问题(2005-04-02 20:42:00)

摘要:#include<stdio.h> #include"math.h" void seekroot (float a,float b,float c) { float m,term1,term2; if(a==0) if(b==0) printf("the answer not exist.\n"); else printf("the answer is %f\n",-c/b); else   {   m=b*b-4*a*c;   if(m>0)   { term1=(-b+sqrt(m))/(2*a); term2=(-b-sqrt(m))/(2*a); printf("the root is %f and %f",term1,term2);} else printf("the real root not exsit !\n");    } } main() { float d,e,f; printf("please input three numbers;\n"); scanf("%f%f%f",&d,&e,&f); seekroot(d,e,f); ......

阅读全文(4154) | 评论:0

起泡法排序(2005-04-02 20:40:00)

摘要:#include<stdio.h> void enter(float a[],int n) { int i; printf("please input numbers:\n"); for(i=0;i<n;i++) scanf("%f",&a[i]); printf("\nthe origin numers are:\n"); for(i=0;i<n;i++) printf("%f",a[i]); printf("\n"); return; } void bubble(float a[],int n) { int i,j,t,m; float k; for(i=0;i<n;i++) { t=n-i-1; for(j=0;j<t;j++) if(a[j]>a[j+1]) { k=a[j]; a[j]=a[j+1]; a[j+1]=k; } } printf("the versed  numbers are:\n"); for(m=0;m<n;m++) printf("%f",a[m]); printf("\n"); } main() { int n; float a[12]; printf("how many numbers do you want to input?number:\n"); scanf("%d",&n); enter(a,n); bubble(a,n); ......

阅读全文(6599) | 评论:0

兔子繁殖问题(2005-04-02 20:39:00)

摘要:#include<stdio.h> void trade (a,b,c) { b=c; a=b; } main() { int n,i,fbn,fbn1,fbn2; printf("please input the month which you want to know:"); scanf("%d\n",&n); if(n>13 || n<1) printf("error due to the wrong input !\n"); else if(n==1|| n==2)         printf("the total number of the rabbits are 1.\n");         else         fbn1=fbn2=1;             for(i=3;i<=n;i++)             {          fbn=fbn1+fbn2;                   fbn2=fbn1;       fbn1=fbn;             }   &nb......

阅读全文(4860) | 评论:0

将十进制数转化为8进制(2005-04-02 20:38:00)

摘要:#define STACK_INIT_SIZE  8 #define STACKINCRMENENT 4 #include <stdio.h> #include<math.h> typedef struct{ int *base; int *top; int stacksize; }sqstack; typedef sqstack *stacklist; stacklist p; stacklist initstack (stacklist p) { p->base=(int *)malloc(STACK_INIT_SIZE *sizeof(int)); if(!p->base)   {    printf("overflow!\n");    exit(0);   }   p->top=p->base; p->stacksize=STACK_INIT_SIZE ; printf("succeed in applying for a room!\n"); return(p); }   stacklist push (stacklist p,int m) { if(p->top-p->base>=p->stacksize)    {     p->base=(int *)realloc(p->base,(p->stacksize+STACKINCRMENENT)*sizeof(int));     if(!p->base)       {        printf("overflow leads to failure!\n");     exit(0);  &nb......

阅读全文(3308) | 评论:0