(central university of finance and economics)

1997年

1、

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int m,n;
    int two_f,three_f;
    two_f=2;
    three_f=3;

    printf("Enter m and n:\n");
    printf("m=");
    scanf("%d",&m);
    printf("n=");
    scanf("%d",&n);

    while(m&&n){
        if(two_f<three_f){
            printf("%d ",two_f);
            two_f*=2;
            m--;
        }else{
            printf("%d ",three_f);
            three_f*=3;
            n--;
        }
    }

    while(m){
        printf("%d ",two_f);
        two_f*=2;
        m--;
    }

    while(n){
        printf("%d ",three_f);
        three_f*=3;
        n--;
    }
    printf("\n");
    return 0;
}

2、

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include<malloc.h>
 4 
 5 typedef struct number{
 6     struct number *next;
 7     int number;
 8 }NUM;
 9 
10 NUM* CreSinList(int a[],int n){
11     int i;
12     NUM *head;
13     NUM *r,*p;//尾插法
14     head=(NUM *)malloc(sizeof(NUM));
15     head->next=NULL;
16     head->number='\0';
17     r=head;
18 
19     for(i=0;i<n;i++){
20         p=(NUM *)malloc(sizeof(NUM));
21         p->number=a[i];
22         p->next=NULL;
23         r->next=p;
24         r=p;
25     }
26     r->next=NULL;
27     return head;
28 }
29 
30 void Del(NUM *pre,NUM *cur){
31     printf("yes");
32     pre->next=cur->next;
33     free(cur);
34 }
35 
36 void Prin(NUM *cur){
37     printf("%d ",cur->number);
38 }
39 int FindNum(NUM *head,NUM *pre,NUM *cur,int key){
40 
41    int find=0;
42    pre=head;
43    cur=pre->next;
44    while(cur!=NULL){
45      if(cur->number==key){
46         Prin(cur);
47         Del(pre,cur);
48         find=1;
49         break;
50      }
51      pre=cur;
52      cur=cur->next;
53    }
54    return find;
55 }
56 int main()
57 {
58 
59 
60     int a[]={1,2,3,4,5,6,7,8,9,10};
61     int n=sizeof(a)/sizeof(int);
62     int keynum;
63     int find=0;
64     NUM *head,*pre,*cur;
65 
66     head=CreSinList(a,n);
67     //head=head->next;//(找了几十分钟就是多加了这条语句,导致运行完一个,头结点到一下个断了)
68     pre=head;
69     cur=head->next;
70     printf("Enter a integer(1-10) you want find:");
71     scanf("%d",&keynum);
72     while(1){
73         if(cur==NULL){
74             printf("Sorry the List is NULL.\n");
75             break;
76         }
77         find=FindNum(head,pre,cur,keynum);
78         if(find){
79             printf("Find it,and already deleted!\n");
80         }else{
81             printf("there is not the number you had entered in the sort from low to high,please enter other number.\n");
82         }
83          printf("Enter a integer(1-10) you want find:");
84          scanf("%d",&keynum);
85         pre=head;//每次从开头找
86         cur=head->next;
87     }
88     return 0;
89 }