首页 > 代码库 > ccc

ccc

课本第291页第4题
#include<stdio.h>

void main()
{
    int n, m, i, k;
    int p_begin;
    int arr[100];
    
    scanf("%d", &n);
    for(i = 0; i < n; i ++)
        scanf("%d", &arr[i]);
    scanf("%d", &m);
    p_begin = 0;
    p_begin = p_begin - m < 0?
    -(p_begin - m) % n : (p_begin - m) % n;
    for(i = p_begin, k = 0; k < n; k++){
        if(i >= n) i = 0;
        printf("%d ", arr[i++]);
    }
}

课本第291页第11题
#include<stdio.h>

void main()
{
    int i = 0;
    int strcmp(char *, char *);
    void sort(char *p[], int n);
    char s[100][100];
    char *p[10];
    
    // input strings 
    for(i = 0; i < 10; i ++)
        scanf("%s", s[i]);
    for(i = 0; i < 10; i ++)
        p[i] = s[i];
    
    sort(p ,10);
    // display outputs on console
    for(i = 0; i < 10; i ++)
        printf("%s\n", p[i]);
}

int strcmp(char *s, char *t)
{
    for( ; *s == *t; s++, t++)
        if(*s == \0)
            return 0;
    return *s - *t;
}

void sort(char *p[], int n)
{
    char *temp = "hello world!";
    
    for(int i = 0; i < n ; i ++)
        for(int j = 0; j < n - i - 1; j ++)
            if(strcmp(p[j] , p[j+1]) > 0){
                temp = p[j];
                p[j] = p[j+1];
                p[j+1] = temp;
            }
    return;
}

课本习题 
#include<stdio.h>
#include<ctype.h>

void main()
{
    int i, j;
    char c;
    char s[100][100];

    i = 0;
    c = a;
    while(c != EOF){
        while(!isdigit(c = getchar()))
            ;
        j = 0;
        s[i][j++] = (char)c;   // 为了判断是不是数字要多读一个。
        while(isdigit(c = getchar()))
            s[i][j++] = (char)c;
        s[i++][j] = \0;
    }

    printf("%d digits\n", i);
    for(int k = 0; k < i; k ++)
        printf("%s\n", s[k]);
}

课本第292页 18题
#include<stdio.h>

void main()
{
    char *p[] = {
        "January",
        "February",
        "March",
        "April",
        "May",
        "June",
        "July",
        "August",
        "September",
        "October",
        "November",
        "December"
    };
    
    int month;
    
    scanf("%d", &month);
    printf("%s\n", p[month-1]);
}

 

ccc