1,题目:编写程序,实现strcmp()相同功能myStrcmp()函数
strcmp函数
其一般形式为:strcmp(字符串1,字符串2)
strcmp的作用是比较字符串1和字符串2。
例如:strcmp(str1,str2);
strcmp(″China″,″Korea″);
strcmp(str1,″Beijing″);
比较的结果由函数值带回
(1) 如果字符串1=字符串2,函数值为0。
(2) 如果字符串1>字符串2,函数值为一正整数。
(3) 如果字符串1<字符串2,函数值为一负整数。
注意:对两个字符串比较,不能用以下形式:
if(str1>str2)
printf(″yes″);
而只能用
if(strcmp(str1,str2)>0)
printf(″yes″);
2.题目:编写程序,将十进制转换为8进制并输出(不允许使用printf("%o"))
1 #include <stdio.h>
2
3 int main()
4 {
5 int a[100];
6 int n,t,i,j,k;
7 printf ("please input the nameber\n");
8 scanf("%d",&n);
9 for(t=0;n>0;n=n/8)
10 {
11 k=n%8;
12 a[t]=k;
13 t++;
14 }
15 printf("shuchubajinzhishu\n");
16 for(j=t-1;j