课本第291页第4题
#include<stdio.h> void main()
{
int n, m, i, k;
int p_begin;
int arr[]; scanf("%d", &n);
for(i = ; i < n; i ++)
scanf("%d", &arr[i]);
scanf("%d", &m);
p_begin = ;
p_begin = p_begin - m < ?
-(p_begin - m) % n : (p_begin - m) % n;
for(i = p_begin, k = ; k < n; k++){
if(i >= n) i = ;
printf("%d ", arr[i++]);
}
} 课本第291页第11题
#include<stdio.h> void main()
{
int i = ;
int strcmp(char *, char *);
void sort(char *p[], int n);
char s[][];
char *p[]; // input strings
for(i = ; i < ; i ++)
scanf("%s", s[i]);
for(i = ; i < ; i ++)
p[i] = s[i]; sort(p ,);
// display outputs on console
for(i = ; i < ; i ++)
printf("%s\n", p[i]);
} int strcmp(char *s, char *t)
{
for( ; *s == *t; s++, t++)
if(*s == '\0')
return ;
return *s - *t;
} void sort(char *p[], int n)
{
char *temp = "hello world!"; for(int i = ; i < n ; i ++)
for(int j = ; j < n - i - ; j ++)
if(strcmp(p[j] , p[j+]) > ){
temp = p[j];
p[j] = p[j+];
p[j+] = temp;
}
return;
} 课本习题
#include<stdio.h>
#include<ctype.h> void main()
{
int i, j;
char c;
char s[][]; i = ;
c = 'a';
while(c != EOF){
while(!isdigit(c = getchar()))
;
j = ;
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 = ; 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-]);
}
习题六 int strcmp(char *s, char *t)
{
for( ; *s == *t; s++, t++)
if(*s == '\0')
return ;
return *s - *t;
} 习题四 #include<stdio.h> void main()
{
int n, m, i, k;
int p_begin;
int arr[]; scanf("%d", &n);
for(i = ; i < n; i ++)
scanf("%d", &arr[i]);
scanf("%d", &m);
p_begin = ;
p_begin = p_begin - m < ?
-(p_begin - m) % n : (p_begin - m) % n;
for(i = p_begin, k = ; k < n; k++){
if(i >= n) i = ;
printf("%d ", arr[i++]);
}
}
D:\lab_>a 习题三 #include<stdio.h> int main()
{
int arr[];
int m, n, i;
int sum = ; for(i = ; i < ; i ++)
scanf("%d", arr+i);
scanf("%d %d", &m, &n);
for(i = m; i <= n; i ++)
sum += *(arr+i);
printf("sum = %d", sum);
return ;
} D:\lab_>a sum = 习题七 #include<stdio.h>
#define MAXSIZE 1000 void insert(char *, char *, char c);
int length(char *s);
char ori_str[MAXSIZE]; void main()
{
char insert_str[MAXSIZE];
char c;
// inputs
gets(ori_str);
gets(insert_str);
scanf("%c", &c);
insert(ori_str, insert_str, c);
// outputs
printf("%s", ori_str);
} void insert(char s[], char t[], char c)
{
int k, i, j;
int p_last = length(s) + ;
int length_t = length(t); k = ;
//printf("a");
while(s[k] != '\0'){
if(s[k] == c){
for(i = p_last; i >= k+; i --)
s[i+length_t] = s[i];
//printf("b");
j = ;
for(i = k+; i <= k+length_t; i ++)
s[i] = t[j ++];
}
k += length_t;
}
} int length(char *s)
{
int n; for(n = ; *s != '\0'; s++, n++)
;
return n;
} D:\lab_>a
aaaaa
d
a
adadadad