# 第三次作业

## 作业一

### 题目6-1输出月份英文名

1。设计思路

2。实验代码

#include <stdio.h>
char *getmonth( int n )
{
char *month[13]={"January","February","March","April","May","June","July","August","September","October","November","December"};
int i=0;
for(i=0;i<13;i++)
{
if(i==0)
{
continue;
}else if(n==i)
{
return *(month+i-1);
}
}
if(n>=13||n<=0)
{
return NULL;
}
}


3。没问题

### 6-2 查找星期

int getindex( char *s ) {
char day[7][MAXS]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
int i;
for(i=0;i<7;i++) {
if(strcmp(*(day+i),s)==0)
return (i);
}
if(i==7)
return (-1);
}


### 6-3计算最长的字符串长度

int max_len( char *s[], int n )
{
int i,l=0;
for(i=0;i<n;i++)
{
if(l<strlen(*(s+i)))
{
l=strlen(*(s+i));
}
}
return l;
}


### 题目6-4指定位置输出字符串

char *match( char *s, char ch1, char ch2 )
{
int i=0,j=0;
char *p=NULL;
for(i=0;*(s+i)!='\0';i++)
{
if(s[i]==ch1)
{
p=&s[i];
for(j=i;*(s+j)!='\0';j++)
{
if(s[j]!=ch2)
{
printf("%c", s[j]);
}
if(s[j]==ch2)
{
printf("%c\n", s[j]);
return p;
}
}
printf("\n");
return p;
}
}
if(s[i] == '\0')
p = &s[i];
printf("\n");
return p;
}


## 作业二学习总结和进度

posted @ 2018-04-22 20:15  金海东123  阅读(138)  评论(0编辑  收藏  举报