• 第七章


    7-1

    #include<stdio.h>
    int main(void)
    {
        int count[9];
        int i,response;
        for(i=1;i<=8;i++)
            count[i]=0;
        for(i=1;i<=8;i++){
            printf("input your response:");
            scanf("%d",&response);
            if(response<1||response>8)
                printf("this is a bad response:%d
    ",response);
            else
                count[response]++;
        }
        printf("result:
    ");
        for(i=1;i<=8;i++)
            printf("%4d%4d
    ",i,count[i]);
    
        return 0;
    }

    7-2

    #include<stdio.h>
    int main(void)
    {
        int i;
        int fib[10]={1,1};
        for(i=2;i<10;i++)
            fib[i]=fib[i-1]+fib[i-2];
        for(i=0;i<10;i++){
            printf("%6d",fib[i]);
            if((i+1)%5==0)
                printf("
    ");
        }
    
        return 0;
    }

    7-3

    #include<stdio.h>
    int main(void)
    {
        int i,flag,x;
        int a[5];
        printf("Enter 5 integers:");
        for(i=0;i<5;i++)
            scanf("%d",&a[i]);
        printf("Enter x:");
        scanf("%d",&x);
        flag=0;
        for(i=0;i<5;i++)
            if(a[i]==x){
                printf("Index is %d
    ",i);
                flag=1;
                break;
            }
            if(flag==0)
                printf("Not Found
    ");
    
            return 0;
    }

    7-4

    #include<stdio.h>
    int main(void)
    {
        int i,index,n;
        int a[10];
        printf("Enter n:");
        scanf("%d",&n);
        printf("Enter %d integers:",n);
        for(i=0;i<n;i++)
            scanf("%d",&a[i]);
        index=0;
        for(i=1;i<n;i++)
            if(a[i],a[index])
                index=i;
    
            printf("min is %d	sub is %d
    ",a[index],index);
    
            return 0;
    }

    7-5

    #include<stdio.h>
    int main(void)
    {
        int i,index,k,n,temp;
        int a[10];
        printf("Enter n:");
        scanf("%d",&n);
        printf("Enter %d intgers:",n);
        for(i=0;i<n;i++)
            scanf("%d",&a[i]);
        for(k=0;k<n-1;k++){
            index=k;
            for(i=k+1;i<n;i++)
                if(a[i]<a[index]) index=i;
                temp=a[index];
                a[index]=a[k];
                a[k]=temp;
        }
        printf("After sorted:");
        for(i=0;i<n;i++)
            printf("%d",a[i]);
        printf("
    ");
    
        return 0;
    }

  • 相关阅读:
    js的同步和异步
    事件三
    事件2
    JS作用域题
    游戏之乐
    NSTimer(2)
    NSTimer
    理解 Objective-C Runtime
    iOS系统安全机制概览
    Which is the best of GCD, NSThread or NSOperationQueue?
  • 原文地址:https://www.cnblogs.com/chcb/p/3354371.html
Copyright © 2020-2023  润新知