1.move the window
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <windows.h>
4
5 //open
6 void open()
7 {
8 ShellExecuteA(0, "open", "\"C:\\Users\\silve\\Desktop\\相关资料文章链接.txt\"", 0, 0, 1);
9 }
10
11 //close
12 void close()
13 {
14 //system();
15 }
16
17 //move recursive
18 void move_recursive(HWND win , int x)
19 {
20 if ( x== 1000)
21 {
22 return;
23 }
24 else
25 {
26 SetWindowPos(win ,NULL , x, x* 800/1000 , 200,300,1 );
27 x++;
28 move_recursive( win , x);
29 }
30
31 }
32
33 void move()
34 {
35 //打开句柄
36 HWND win = FindWindowA("Notepad", "相关资料文章链接.txt - 记事本");
37
38 if (win == NULL)
39 {
40 printf("window not found");
41 }
42 else
43 {
44 //five loop
45
46 //for循环 左边->右边
47 {
48 for (int i = 0; i < 1000; i++)
49 {
50 SetWindowPos(win , NULL , i,0, 200, 300, 1);
51 }
52 }
53
54 //while 上->下
55 {
56 int j = 0;
57 while (j < 800)
58 {
59 SetWindowPos(win , NULL , 1000, j , 200, 300, 1);
60 j++;
61 }
62 }
63
64 //do while 右->左边
65 {
66 int k = 1000;
67 do {
68 SetWindowPos(win , NULL , k , 800 , 200, 300 , 1);
69 k--;
70 } while (k);
71 }
72
73 //goto 下->上
74 {
75 int m = 800;
76 ups: if (m)
77 {
78 SetWindowPos(win , NULL , 0, m, 200, 300, 1);
79 m--;
80 goto ups;
81 }
82 }
83
84 // recursive 递归
85 {
86 move_recursive( win , 0);
87 }
88
89 }
90 }
91
92 int main()
93 {
94 open();
95 Sleep(2000);
96 move();
97
98 getchar();
99 return 0;
100 }
2. recursive and loop
#include <stdio.h>
//判断数组是不是递增数组
int main()
{
int arr[] = { 1,2,3,4,5,6,7,0 };
int len = sizeof(arr) / sizeof(arr[0]);
//常规方法判断
int flag = 1;
for (int i = 0; i<len-1; i++)
{
if (arr[i] >= arr[i+1])
{
flag = 0;
break;
}
}
printf("这个数组 %s 递增的数组" , flag == 0?"不是":"是" );
//递归判断
getchar();
return 0;
}
recursive
//int arr[9] = { 1,2,3,4,5,6,7,8,9 };
int arr[9] = { 9,8,7,6,5,4,3,2,1 };
int isincrease(int i)
{
//索引是8, i+1 最大是8, i最大是7
if (i == 7)
{
return arr[i]<arr[i+1];
}
else
{
return (arr[i] < arr[i + 1]) && isincrease(i+1);//逻辑&& 串联条件
}
}
int isdecrease(int n)
{
if (n==7)
{
return arr[n] > arr[n + 1];
}
else
{
return arr[n] > arr[n + 1] && isdecrease(n + 1);
}
}
int main()
{
int res = isincrease(0);
printf("%s" , res == 1?"is increase array" : "is not increase array");
printf("\n");
res = isdecrease(0);
printf("%s", res == 1 ? "is decrease array" : "is not decrease array");
getchar();
return 0;
}
3.分解质因数
1 #define _CRT_SECURE_NO_WARNINGS
2 #include <stdio.h>
3 #include <stdlib.h>
4
5 void prim(int num)
6 {
7 int i = 0;
8 //质因数最大的范围是一半 99 -- <50
9 for (i = 2; i < (num/2 + 1) ; i++)
10 {
11 //如果能整除 跳出循环
12 if (num % i == 0)
13 {
14 break;
15 }
16 }
17
18 if (i == (num / 2 + 1))
19 {
20 printf("%d", num);
21 }
22 else
23 {
24 printf("%d %s ", i, "*");
25 prim(num / i);
26 }
27
28
29 }
30
31
32 int main()
33 {
34 //input data
35 int num ;
36 scanf("%d" , &num);
37
38 //分解质因数
39 prim(num);
40
41 system("pause");
42 return 0;
43 }
4. recursive 判断是否是回文字符串
1 #define _CRT_SECURE_NO_WARNINGS
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5
6
7 int is_reversestring( char * str , int length)
8 {
9 if (length <= 1)
10 {
11 return 1;
12 }
13 else if (str[0] == str[length - 1])
14 {
15 return is_reversestring( str+1 , length -2);
16 }
17 else
18 {
19 return 0;
20 }
21 }
22
23
24
25 int main()
26 {
27 char str[100];
28 gets(str);
29 printf("%d", is_reversestring(str, strlen(str)));
30 system("pause");
31 return 0;
32 }
posted on 2017-06-23 10:00
silvercell 阅读(114)
评论(0) 编辑 收藏 引用 所属分类:
c/cpp_codes