Skip to content

Commit b3b7865

Browse files
committed
添加基本技能
1 parent cea8d1c commit b3b7865

File tree

2 files changed

+502
-0
lines changed

2 files changed

+502
-0
lines changed

1基本技能开发技巧/10.c

Lines changed: 310 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,310 @@
1+
/****************************************
2+
技巧:01
3+
十进制数转化为十六进制
4+
****************************************/
5+
/*
6+
#include <stdio.h>
7+
int main(int argc, char *argv[])
8+
{
9+
int i;
10+
printf ("please input decimalism number:\n");
11+
scanf("%d",&i);
12+
printf ("the hex number is %x\n",i);
13+
return 0;
14+
}
15+
*/
16+
/****************************************
17+
技巧:02
18+
N进制转换为十进制
19+
****************************************/
20+
/*
21+
#include <stdio.h>
22+
#include <string.h>
23+
main()
24+
{
25+
long t1;
26+
int i,n,t,t3;
27+
char a[100];
28+
printf ("please input a number string:\n");
29+
gets(a); //输入N进制数存到数组a中
30+
strupr(a); //将a中的小写字母转换成大写字母
31+
t3=strlen(a);
32+
t1=0;
33+
printf ("please input n(2or8or16):\n");
34+
scanf("%d",&n);
35+
for (i=0; i<t3; i++)
36+
{
37+
if (a[i]-'0'>=n&&a[i]<'A'||a[i]-'A'+10>=n)//判断输入的数据和进制数是否相等
38+
{
39+
printf ("data error!!");
40+
exit(0); //推出程序
41+
}
42+
if (a[i] >= '0'&&a[i] <= '9') //判断是否为数字
43+
t=a[i]-'0';
44+
else if(n>=11&&(a[i]>='A'&&a[i]<='A'+n-10)) //判断是否为字母o
45+
t=a[i]-'A'+10;
46+
t1=t1*n+t; //求出最终转换成十进制的值
47+
}
48+
printf ("the decimal is %ld\n",t1);
49+
return 0;
50+
}
51+
*/
52+
/****************************************
53+
技巧03:IP地址形式输出
54+
****************************************/
55+
/*
56+
#include <stdio.h>
57+
int bin_dec(int x,int n) //将而进制转换成十进制
58+
{
59+
if(n==0)
60+
return 1;
61+
return x*bin_dec(x,n-1);
62+
}
63+
int main(int argc, char *argv[])
64+
{
65+
int i;
66+
int ip[4]={0};
67+
char a[33];
68+
printf ("please input binary number:\n");
69+
scanf("%s",a);
70+
for (i=0; i<8; i++)
71+
{
72+
if (a[i]=='1')
73+
{
74+
ip[0]+=bin_dec(2,7-i);
75+
}
76+
}
77+
for (i=8; i<16; i++)
78+
{
79+
if (a[i]=='1')
80+
{
81+
ip[1]+=bin_dec(2,15-i);
82+
}
83+
}
84+
for (i=16; i<24; i++)
85+
{
86+
if (a[i]=='1')
87+
{
88+
ip[2]+=bin_dec(2,23-i);
89+
}
90+
}
91+
for (i=24; i<32; i++)
92+
{
93+
if (a[i]=='1')
94+
{
95+
ip[3]+=bin_dec(2,31-i);
96+
}
97+
if (a[i]=='\0')
98+
{
99+
break;
100+
}
101+
}
102+
printf ("ip:");
103+
printf ("%d.%d.%d.%d\n",ip[0],ip[1],ip[2],ip[3]);
104+
return 0;
105+
}
106+
*/
107+
/****************************************
108+
技巧04:数字由小到大排序
109+
****************************************/
110+
/*
111+
#include <stdio.h>
112+
int main(int argc, char *argv[])
113+
{
114+
int a,b,c,t;
115+
printf ("please input a,b,c:\n");
116+
scanf("%d%d%d",&a,&b,&c);
117+
if (a>b)
118+
{
119+
t=a;
120+
a=b;
121+
b=t;
122+
}
123+
if (a>c)
124+
{
125+
t=a;
126+
a=c;
127+
c=t;
128+
}
129+
if (b>c)
130+
{
131+
t=b;
132+
b=c;
133+
c=t;
134+
}
135+
printf ("the order of the number is:\n");
136+
printf ("%d %d %d\n",a,b,c);
137+
return 0;
138+
}
139+
*/
140+
/****************************************
141+
技巧05:阶梯问题
142+
****************************************/
143+
/*
144+
#include <stdio.h>
145+
int main(int argc, char *argv[])
146+
{
147+
int i;
148+
for (i=100; i<1000; i++)
149+
{
150+
if(i%2==1&&i%3==2&&i%5==4&&i%6==5&&i%7==0)
151+
printf ("the number of the stairs is %d\n",i);
152+
}
153+
return 0;
154+
}
155+
*/
156+
/****************************************
157+
技巧06:判断润年
158+
****************************************/
159+
/*
160+
#include <stdio.h>
161+
int main(int argc, char *argv[])
162+
{
163+
int year;
164+
printf ("please input the year:\n");
165+
scanf("%d",&year);
166+
if((year%4==0&&year%100!=0)||year%400==0)
167+
printf ("%d is a leap year\n",year);
168+
else
169+
printf ("%d is not a leap year\n",year);
170+
return 0;
171+
}
172+
*/
173+
/****************************************
174+
技巧07:对调数问题
175+
****************************************/
176+
/*
177+
#include <stdio.h>
178+
int main(int argc, char *argv[])
179+
{
180+
int x,y,z,x1,y1,z1,i,k,n,j=0;
181+
while(1)
182+
{
183+
printf ("please input an integer\n");
184+
scanf("%d",&n);
185+
if (n<=10||n>=100)
186+
{
187+
printf ("data error\n");
188+
continue;
189+
}
190+
else if (n%10==0)
191+
{
192+
printf ("data error\n");
193+
continue;
194+
}
195+
else
196+
{
197+
x=n/10;
198+
y=n%10;
199+
z=10*y+x;
200+
break;
201+
}
202+
}
203+
for (i=11; i<100; i++)
204+
{
205+
if (i%10==0)
206+
continue; //结束本次循环
207+
else
208+
{
209+
x1=i/10;
210+
y1=i%10;
211+
z1=10*y1+1;
212+
//判断是否满足等式条件
213+
if (n+i==z+z1&&n!=z1)
214+
{
215+
printf ("%d+%d=%d+%d\n",n,i,z,z1);
216+
j++;
217+
}
218+
else
219+
continue;
220+
}
221+
}
222+
if(j==0)
223+
printf ("inexistince\n");
224+
return 0;
225+
}
226+
*/
227+
/****************************************
228+
技巧08:评定成绩等级
229+
****************************************/
230+
/*
231+
#include <stdio.h>
232+
int main(int argc, char *argv[])
233+
{
234+
int score;
235+
printf ("please enter score(score<=10):");
236+
scanf("%d",&score);
237+
if (score==100)
238+
{
239+
score =90;
240+
}
241+
score = score/10;
242+
switch(score)
243+
{
244+
case 9:
245+
printf ("the grade is A\n");
246+
break;
247+
case 8:
248+
printf ("the grade is B\n");
249+
break;
250+
case 7:
251+
printf ("the grade is C\n");
252+
break;
253+
case 6:
254+
printf ("the grade is D\n");
255+
break;
256+
default:
257+
printf ("the grade is E\n");
258+
}
259+
return 0;
260+
}
261+
*/
262+
/****************************************
263+
技巧09:打印乘法口决表
264+
****************************************/
265+
/*
266+
#include <stdio.h>
267+
int main(int argc, char *argv[])
268+
{
269+
int i,j;
270+
for (i=1; i<=9; i++)
271+
{
272+
for (j=1; j<=i; j++)
273+
{
274+
printf ("%d*%d=%d p",i,j,i*j);
275+
}
276+
printf ("\n");
277+
}
278+
return 0;
279+
}
280+
*/
281+
/****************************************
282+
技巧10:打印杨辉三角
283+
****************************************/
284+
/*
285+
#include <stdio.h>
286+
int main(int argc, char *argv[])
287+
{
288+
int i,j,a[11][11];
289+
for (i=1; i<11; i++)
290+
{
291+
a[i][i]=1;
292+
a[i][1]=1;
293+
}
294+
for (i=3; i<11; i++)
295+
{
296+
for (j=2; j<=i-1; j++)
297+
{
298+
a[i][j]=a[i-1][j-1]+a[i-1][j];
299+
}
300+
}
301+
for (i=1; i<11; i++)
302+
{
303+
for (j=1; j<=i; j++)
304+
printf ("%4d\t",a[i][j]);
305+
printf ("\n");
306+
}
307+
return 0;
308+
}
309+
*/
310+

0 commit comments

Comments
 (0)