C语言基础训练3

1,题目:编写程序,实现strcmp()相同功能myStrcmp()函数strcmp函数其一般形式为:strcmp(字符串1,字符串2)strcmp的作用是比较字符串1和字符串2。例如:strcmp(str1,str2);strcmp(″China″,″Korea″);strcmp(str1,″Beijing″);比较的结果由函数值带回(1) 如果字符串1=字符串2,函数值为0。...
摘要由CSDN通过智能技术生成

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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值