# 6-1 输出月份英文名

1.设计思路

2.实验代码

char *getmonth( int n )
{
char *month[12]={"January","February","March","April","May","June","July","August","September","October","November","December"};
if(n>0&&n<13)
{
return month[n-1];
}else{
return NULL;
}
}


# 6-2 查找星期

1.设计思路

2.实验代码

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


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

1.设计思路

2.实验代码

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


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

1.设计思路

char *match( char *s, char ch1, char ch2 ){

int i=0,j=0,len=0;
char*p=NULL;

len = strlen(s);

for(i=0;i<len;i++){
if(s[i]==ch1){
p=&s[i];
for(j=i;j<len;j++){
if(s[j]!=ch2){
printf("%c", s[j]);
}
if(s[j]==ch2){
printf("%c\n", s[j]);
return p;
}
}
printf("\n");
return p;
}
}
printf("\n");
return s+i;
}


posted on 2018-04-22 15:11  曹佰强  阅读(154)  评论(2编辑  收藏  举报