
C语言
哈哈大笑很倾城
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
2017-7-17 2-2 不使用&&和|| 编写一个与debug1中for循环等价的循环语句
#include<stdio.h> #define debug1 0 #define debug2 1 int i,lim=10; char c,s[10]; enum loop {NO,YES}; enum loop okloop =YES; main() { #if debug1 for(i=0;i<lim-1&&(c=getchar())!='\n'&...原创 2018-07-18 00:29:01 · 150 阅读 · 0 评论 -
2018-7-16 2-1 分别由signed 和unsigned 限定的 char,short,int,long类型变量的取值范围
#include<stdio.h> #include<limits.h> #define debug1 0 //使用debug1 必须包含limits.h #define debug2 1 main() { #if debug1 //signed types printf("signed char min = %d \n",SCHAR_MIN); pr...原创 2018-07-17 00:27:26 · 274 阅读 · 0 评论 -
2017-7-18 2-3 编写函数htoi(s), 将十六进制的字符串(包含0x或0X)转换为与之等价的整形值,字符串中允许包含的数字:0~9,a~f,A~F
#define YES 1 #define NO 0 int htoi(char s[]) { int hexdigit,i,inhex,n; i=0; if(s[i]=='0') { ++i; if(s[i]=='x' || s[i]=='X') { ++i; } } n=0; inhex=YES; for( ;inhex==YES; ++i) {...原创 2018-07-19 00:29:15 · 656 阅读 · 0 评论 -
2017-7-18 2-4 编写函数squeeze(s1,s2), 将字符串s1中任何与字符串s2中字符匹配的字符都删除。
#include<stdio.h> #include<string.h> /************************************************************************************* 编写函数squeeze(s1,s2), 将字符串s1中任何与字符串s2中字符匹配的字符都删除。 *********...原创 2018-07-20 01:03:38 · 795 阅读 · 1 评论 -
2017-7-28 2-6 编写函数setbits(x,p,n,y),该函数返回对x执行下列操作后的结果值: 将x中从第p位开始的n个(二进制)位设置为y中最右边的n位的值,x的其余位保持不变
#include <stdio.h> #include <stdlib.h> unsigned setbits(unsigned int x,int p,int n,unsigned int y) { return ( x & (~((~(~0<<n))<<(p+1-n))) ) | ...原创 2018-07-28 16:54:25 · 750 阅读 · 0 评论 -
2017-7-28 2-7 编写函数invert(x,p,n),该函数返回对x执行下列操作后的结果值:将x中从第p位开始的n个(二进制)位求反,x的其余位保持不变
#include <stdio.h> #include <stdlib.h> unsigned invert(unsigned int x,int p,int n) { return x^ (~(~0<<n)<<(p+1-n)); //异或操作 1^1=0 0^0=0 1^0=1 0^1=1 //用或操作,已完成,比较麻烦 ...原创 2018-07-28 17:40:41 · 512 阅读 · 0 评论 -
2017-7-28 2-8 编写函数rightrot(x,n),该函数返回将x循环右移(即从最右端移出的位将从最左端移入)n位后所得到的值
#include <stdio.h> #include <stdlib.h> int wordlength(void) { int t; unsigned v=(unsigned)~0;// 这里要尤其注意unsigned的使用 ,unsigned 左移 右移都补0 for(t=1;(v=v>>1)>0;t++) { ...原创 2018-07-28 18:14:24 · 949 阅读 · 0 评论 -
2017-7-28 2-5 编写函数any(s1,s2), 将字符串s2中任一字符在字符串s1中第一次出现的位置作为返回结果,如果s1中不包含s2中的字符,则返回-1
#include <stdio.h> #include <stdlib.h> int any( char s1[], char s2[] ) { int i=0,j=0; for(i=0; s1[i]!='\0'; i++) // ' \0 ' 字符串结束符 { for(j=0; s2[j] != '\0'&& j<...原创 2018-07-28 12:46:06 · 1184 阅读 · 0 评论