题目:
1) 书164页习题1 两字符串拼接
2) 书164页习题2 两字符串比较大小
3) 10个城市对应20~29的长途区号,将用三种方法表示的数据分别两列输出,左边是区号,右边是城市名:
city1[]={"Guangzhou,Shanghai,Tianjin,Chongqing,Shenyang,Nanjing,NO,Wuhan,Chengdu,Xi_an"}
city2[][20]={"Guangzhou","Shanghai","Tianjin","Chongqing","Shenyang","Nanjing","NO","Wuhan","Chengdu","Xi_an"}
*city[]={"Guangzhou","Shanghai","Tianjin","Chongqing","Shenyang","Nanjing","NO","Wuhan","Chengdu","Xi_an"}
全部C程序合并为一个cpp文件,调试正确后粘贴在下框内,提交作业。
--------------------------------------------------------------------------------
提交作业时间:2004-4-21 11:23:28
/* ============== Program Description ============= */
/* [i]清翔兔 */
/* ================================================== */
# include <stdio.h>
void LB_1()
{ char a1[99],a2[99],b[99];int i,j=0;char *p1=a1,*p2=a2,*pb=b;
printf("input a $:"); scanf("%s",a1);
printf("another $:"); scanf("%s",a2);
for (i=0;*(p1+i)!='/0';i++) *(pb+i)=*(p1+i);
for (;*(p2+j)!='/0';i++,j++) *(pb+i)=*(p2+j);
*(pb+i)='/0';
for (i=0;b[i]!='/0';i++) printf("%c",b[i]);
printf("/n/n");
}
void LB_2()
{
char str1[50],str2[50];
char *ps1=str1,*ps2=str2;
printf("input a $:");
scanf("%s",ps1);
printf("another $:"); scanf("%s",ps2);
while(*ps1!='/0'&&*ps2!='/0')
{
if(*ps1!=*ps2) break;
ps1++;
ps2++;
}
if(*ps2>*ps1)
printf("string1 < string2/n");
else if(*ps2 < *ps1)
printf("string1 > string2/n");
else
printf("string1 = string2/n");
}
void LB_3()
{
int i,j=0;
char city1[]={"Guangzhou,Shanghai,Tianjin,Chongqing,Shenyang,Nanjing,No,Wuhan,Chengdu,Xi_an,"};
char city2[][20]={"Guangzhou","Shanghai","Tianjin","Chongqing","Shenyang","Nanjing","No","Wuhan","Chengdu","Xi_an"};
char *city[]={"Guangzhou","Shanghai","Tianjin","Chongqing","Shenyang","Nanjing","No","Wuhan","Chengdu","Xi_an"};
printf("第1种");
for (i=0;city1[i]!='/0';i++)
{
if (city1[i]<90&&city1[i]>65)
{ printf("/n"); printf("02%d ",j);j++;}
if (city1[i]!=44)
printf("%c",city1[i]);
}
printf("/n第2种/n");
for (i=0;i<10;i++)
printf("02%d %s/n", i,city2[i]);
printf("第3种/n");
for (i=0;i<10;i++)
printf("02%d %s/n", i,city[i]);
}
void main()
{
LB_1();
LB_2();
LB_3();
}
得分:7 点评:/
1) 书164页习题1 两字符串拼接
2) 书164页习题2 两字符串比较大小
3) 10个城市对应20~29的长途区号,将用三种方法表示的数据分别两列输出,左边是区号,右边是城市名:
city1[]={"Guangzhou,Shanghai,Tianjin,Chongqing,Shenyang,Nanjing,NO,Wuhan,Chengdu,Xi_an"}
city2[][20]={"Guangzhou","Shanghai","Tianjin","Chongqing","Shenyang","Nanjing","NO","Wuhan","Chengdu","Xi_an"}
*city[]={"Guangzhou","Shanghai","Tianjin","Chongqing","Shenyang","Nanjing","NO","Wuhan","Chengdu","Xi_an"}
全部C程序合并为一个cpp文件,调试正确后粘贴在下框内,提交作业。
--------------------------------------------------------------------------------
提交作业时间:2004-4-21 11:23:28
/* ============== Program Description ============= */
/* [i]清翔兔 */
/* ================================================== */
# include <stdio.h>
void LB_1()
{ char a1[99],a2[99],b[99];int i,j=0;char *p1=a1,*p2=a2,*pb=b;
printf("input a $:"); scanf("%s",a1);
printf("another $:"); scanf("%s",a2);
for (i=0;*(p1+i)!='/0';i++) *(pb+i)=*(p1+i);
for (;*(p2+j)!='/0';i++,j++) *(pb+i)=*(p2+j);
*(pb+i)='/0';
for (i=0;b[i]!='/0';i++) printf("%c",b[i]);
printf("/n/n");
}
void LB_2()
{
char str1[50],str2[50];
char *ps1=str1,*ps2=str2;
printf("input a $:");
scanf("%s",ps1);
printf("another $:"); scanf("%s",ps2);
while(*ps1!='/0'&&*ps2!='/0')
{
if(*ps1!=*ps2) break;
ps1++;
ps2++;
}
if(*ps2>*ps1)
printf("string1 < string2/n");
else if(*ps2 < *ps1)
printf("string1 > string2/n");
else
printf("string1 = string2/n");
}
void LB_3()
{
int i,j=0;
char city1[]={"Guangzhou,Shanghai,Tianjin,Chongqing,Shenyang,Nanjing,No,Wuhan,Chengdu,Xi_an,"};
char city2[][20]={"Guangzhou","Shanghai","Tianjin","Chongqing","Shenyang","Nanjing","No","Wuhan","Chengdu","Xi_an"};
char *city[]={"Guangzhou","Shanghai","Tianjin","Chongqing","Shenyang","Nanjing","No","Wuhan","Chengdu","Xi_an"};
printf("第1种");
for (i=0;city1[i]!='/0';i++)
{
if (city1[i]<90&&city1[i]>65)
{ printf("/n"); printf("02%d ",j);j++;}
if (city1[i]!=44)
printf("%c",city1[i]);
}
printf("/n第2种/n");
for (i=0;i<10;i++)
printf("02%d %s/n", i,city2[i]);
printf("第3种/n");
for (i=0;i<10;i++)
printf("02%d %s/n", i,city[i]);
}
void main()
{
LB_1();
LB_2();
LB_3();
}
得分:7 点评:/