Candp_5

变换一个二进制反转位的顺序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <stdio.h>
#include <stdlib.h>
unsigned int reve_bits(unsigned int value)
{
unsigned int i;
unsigned int answer;

answer = 0;

for (i = 1; i != 0; i <<= 1)//可以是循环与机器的子长无关,从而避免了可移植性问题
{
answer <<= 1;//左移一位
if (value & 1)//
{
answer |= 1;
}
value >>= 1;
}

阅读更多

C and P —4

输入多行,输出不相邻重复的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//p64 5 <POINTERS ON C>
#include <stdio.h>
#include <stdlib.h>
int main()
{
char str[128];
char last_str[128];
printf("请输入内容\n");
while (1)
{
gets(str);//遇到换行或文件末尾停
strcpy(last_str, str);
gets(str);//遇到换行或文件末尾停
if (0 == strcmp(last_str, str))
{
while (1)
{
strcpy(last_str, str);
gets(str);//遇到换行或文件末尾停
if (0 != strcmp(last_str, str))
{
printf("重复的为%s\n",last_str);
break;
}
}
}
}
system("pause");
return 0;
}

阅读更多

练习题

判断1000到2000之间的闰年

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//  能4整除不能被100整除,能被400整除
#include <stdio.h>
int main()
{
int i;
int j;
int count=0;
for (i = 1000; i < 2000; i++)
{
if (i % 4 == 0)
{
if (i % 100 != 0)
{
printf("%d ", i);
count++;
}
}
if (i % 400 == 0)
{
printf("%d ", i);
count++;
}
if (count >= 8)
{
count = 0;
printf("\n");
}
}

system("pause");
return 0;
}

阅读更多

编程目标

不知觉的已经大三,继续在编程的道路上前进,学习编程我认为重要的就是实战加思考加写作吧。在平时可以写写博客,练习写作能力。再就是要学好c语言,每天要有几个小时的练习实践。多看看经典的书籍。
一定要有一个学习计划,根据情况合理的制定。

阅读更多