[ create a new paste ] login | about

Link: http://codepad.org/ex13Toxj    [ raw code | output | fork ]

C, pasted on May 5:
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
/* Bài 43 -> 46 /8/SBT Thầy NTTMK:Nhập vào 1 chữ số nguyên dương n,hãy tính:
+ Đếm số lượng chữ số của nó.
+ Liệt kê tất cả các chữ số của nó.
+ Tính tổng tất cả các chữ số của nó.
+ Tính tích tất cả các chữ số của nó.
+ Liệt kê và đếm số lượng các chữ số lẻ của nó.
+ Liệt kê và đếm số lượng các chữ số chẵn của nó. 186.cpp */
/* 

Tác giả: Nguyễn Việt Nam Sơn
Trung tâm đào tạo tin học - Thiết kế phần mềm - Sơn Đẹp Trai: www.SonDepTrai.com

Nguồn source code này Tôi viết vào năm 2012 lúc mới bắt đầu học lập trình C/C++ nên một số cách sẽ không được tối ưu - Bạn chỉ nên dùng trên tinh thần tham khảo thôi nhé.
Mong giúp đỡ được Bạn trên con đường Học Lập Trình.
TẤT CẢ VÌ SỰ THÀNH CÔNG CỦA BẠN

*/
#include<stdio.h>
#include<conio.h>
#define bool

void demchuso(int &n)
{
	do{
		printf("Nhap vao so nguyen duong n(n>=0):n=");
		scanf("%d",&n);
		if(n<0)
			printf("So ban nhap vao khong hop le!Xin vui long nhap lai!\n");
		else
			break;
	}while(n<0);
	if(n>=0&&n<=9)
		printf("\nSo %d co 1 chu so",n);
	if(n>=10&&n<=99)
		printf("\nSo %d co 2 chu so",n);
	if(n>=100&&n<=999)
		printf("\nSo %d co 3 chu so",n);
	if(n>=1000&&n<=9999)
		printf("\nSo %d co 4 chu so",n);
	if(n>=10000&&n<=99999)
		printf("\nSo %d co 5 chu so",n);
}

void lietkechuso(int n)
{
	printf("\nCac chu so cua so %d la:",n); 
		if(n>=0&&n<=9)
			printf("%4d",n);
		if(n>=10&&n<=99)
		{
			int a=n/10;
			int b=n%10;
			printf("%4d",a);
			printf("%4d",b);
		}
		if(n>=100&&n<=999)
		{
			int c=n%10;
			int d=n/10;
			int e=d/10;
			int f=d%10;
			printf("%4d",e);
			printf("%4d",f);
			printf("%4d",c);
		}
		if(n>=1000&&n<=9999)
		{
			int g=n%10;
			int h=n/10;
			int i=h%10;
			int j=h/10;
			int k=j%10;
			int l=j/10;
			printf("%4d",l);
			printf("%4d",k);
			printf("%4d",i);
			printf("%4d",g);
		}
		if(n>=10000&&n<=99999)
		{
			int m=n%10;
			int o=n/10;
			int p=o%10;
			int q=o/10;
			int r=q%10;
			int s=q/10;
			int t=s%10;
			int u=s/10;
			printf("%4d",u);
			printf("%4d",t);
			printf("%4d",r);
			printf("%4d",p);
			printf("%4d",m);
		}
}

void tongcacchuso(int n)
{
	printf("\nTong cac chu so cua so %d la:",n); 
		if(n>=0&&n<=9)
			printf("%4d",n);
		if(n>=10&&n<=99)
		{
			int a=n/10;
			int b=n%10;
			int v=a+b;
			printf("%4d",v);
		}
		if(n>=100&&n<=999)
		{
			int c=n%10;
			int d=n/10;
			int e=d/10;
			int f=d%10;
			int w=e+f+c;
			printf("%4d",w);
		}
		if(n>=1000&&n<=9999)
		{
			int g=n%10;
			int h=n/10;
			int i=h%10;
			int j=h/10;
			int k=j%10;
			int l=j/10;
			int x=l+k+i+g;
			printf("%4d",x);
		}
		if(n>=10000&&n<=99999)
		{
			int m=n%10;
			int o=n/10;
			int p=o%10;
			int q=o/10;
			int r=q%10;
			int s=q/10;
			int t=s%10;
			int u=s/10;
			int y=u+t+r+p+m;
			printf("%4d",y);
		}
}

void tichcacchuso(int n)
{
	printf("\nTich cac chu so cua so %d la:",n); 
		if(n>=0&&n<=9)
			printf("%4d",n);
		if(n>=10&&n<=99)
		{
			int a=n/10;
			int b=n%10;
			int v=a*b;
			printf("%4d",v);
		}
		if(n>=100&&n<=999)
		{
			int c=n%10;
			int d=n/10;
			int e=d/10;
			int f=d%10;
			int w=e*f*c;
			printf("%4d",w);
		}
		if(n>=1000&&n<=9999)
		{
			int g=n%10;
			int h=n/10;
			int i=h%10;
			int j=h/10;
			int k=j%10;
			int l=j/10;
			int x=l*k*i*g;
			printf("%4d",x);
		}
		if(n>=10000&&n<=99999)
		{
			int m=n%10;
			int o=n/10;
			int p=o%10;
			int q=o/10;
			int r=q%10;
			int s=q/10;
			int t=s%10;
			int u=s/10;
			int y=u*t*r*p*m;
			printf("%4d",y);
		}
}

void lietkevademcacchusole(int n)
{
	int dem=0,dem1=0,dem2=0,dem3=0,dem4=0,dem5=0,dem6=0,dem7=0,dem8=0,dem9=0,dem10=0,dem11=0,dem12=0,dem13=0,dem14=0;
	int Co,Co1,Co2,Co3,Co4;
	int tinh,tinh1,tinh2,tinh3;
	bool Co=false;
	bool Co1=false;
	bool Co2=false;
	bool Co3=false;
	bool Co4=false;
	printf("\nCac chu so le cua so %d la:",n);
		if(n>=0&&n<=9)
		{
			if(n%2!=0)
			{
			printf("%4d",n);
			dem++;
			Co=true;
			}
		}
		if(n>=10&&n<=99)
		{
			int a=n/10;
			int b=n%10;
			if(a%2!=0)
			{
			printf("%4d",a);
			dem1++;
			Co1=true;
			}
			if(b%2!=0)
			{
			printf("%4d",b);
			dem2++;
			Co1=true;
			}
		}
		if(n>=100&&n<=999)
		{
			int c=n%10;
			int d=n/10;
			int e=d/10;
			int f=d%10;
			if(e%2!=0)
			{
			printf("%4d",e);
			dem3++;
			Co2=true;
			}
			if(f%2!=0)
			{
			printf("%4d",f);
			dem4++;
			Co2=true;
			}
			if(c%2!=0)
			{
			printf("%4d",c);
			dem5++;
			Co2=true;
			}
		}
		if(n>=1000&&n<=9999)
		{
			int g=n%10;
			int h=n/10;
			int i=h%10;
			int j=h/10;
			int k=j%10;
			int l=j/10;
			if(l%2!=0)
			{
			printf("%4d",l);
			dem6++;
			Co3=true;
			}
			if(k%2!=0)
			{
			printf("%4d",k);
			dem7++;
			Co3=true;
			}
			if(i%2!=0)
			{
			printf("%4d",i);
			dem8++;
			Co3=true;
			}
			if(g%2!=0)
			{
			printf("%4d",g);
			dem9++;
			Co3=true;
			}
		}
		if(n>=10000&&n<=99999)
		{
			int m=n%10;
			int o=n/10;
			int p=o%10;
			int q=o/10;
			int r=q%10;
			int s=q/10;
			int t=s%10;
			int u=s/10;
			if(u%2!=0)
			{
			printf("%4d",u);
			dem10++;
			Co4=true;
			}
			if(t%2!=0)
			{
			printf("%4d",t);
			dem11++;
			Co4=true;
			}
			if(r%2!=0)
			{
			printf("%4d",r);
			dem12++;
			Co4=true;
			}
			if(p%2!=0)
			{
			printf("%4d",p);
			dem13++;
			Co4=true;
			}
			if(m%2!=0)
			{
			printf("%4d",m);
			dem14++;
			Co4=true;
			}
		}
	tinh=dem1+dem2;
	tinh1=dem3+dem4+dem5;
	tinh2=dem6+dem7+dem8+dem9;
	tinh3=dem10+dem11+dem12+dem13+dem14;
	if(Co==true)
		printf("\nSo %d co %d chu so le",n,dem);
	if(Co1==true)
		printf("\nSo %d co %d chu so le",n,tinh);
	if(Co2==true)
		printf("\nSo %d co %d chu so le",n,tinh1);
	if(Co3==true)
		printf("\nSo %d co %d chu so le",n,tinh2);
	if(Co4==true)
		printf("\nSo %d co %d chu so le",n,tinh3);
}

void lietkevademcacchusochan(int n)
{
	int dem=0,dem1=0,dem2=0,dem3=0,dem4=0,dem5=0,dem6=0,dem7=0,dem8=0,dem9=0,dem10=0,dem11=0,dem12=0,dem13=0,dem14=0;
	int Co,Co1,Co2,Co3,Co4;
	int tinh,tinh1,tinh2,tinh3;
	bool Co=false;
	bool Co1=false;
	bool Co2=false;
	bool Co3=false;
	bool Co4=false;
	printf("\nCac chu so chan cua so %d la:",n);
		if(n>=0&&n<=9)
		{
			if(n%2==0)
			{
			printf("%4d",n);
			dem++;
			Co=true;
			}
		}
		if(n>=10&&n<=99)
		{
			int a=n/10;
			int b=n%10;
			if(a%2==0)
			{
			printf("%4d",a);
			dem1++;
			Co1=true;
			}
			if(b%2==0)
			{
			printf("%4d",b);
			dem2++;
			Co1=true;
			}
		}
		if(n>=100&&n<=999)
		{
			int c=n%10;
			int d=n/10;
			int e=d/10;
			int f=d%10;
			if(e%2==0)
			{
			printf("%4d",e);
			dem3++;
			Co2=true;
			}
			if(f%2==0)
			{
			printf("%4d",f);
			dem4++;
			Co2=true;
			}
			if(c%2==0)
			{
			printf("%4d",c);
			dem5++;
			Co2=true;
			}
		}
		if(n>=1000&&n<=9999)
		{
			int g=n%10;
			int h=n/10;
			int i=h%10;
			int j=h/10;
			int k=j%10;
			int l=j/10;
			if(l%2==0)
			{
			printf("%4d",l);
			dem6++;
			Co3=true;
			}
			if(k%2==0)
			{
			printf("%4d",k);
			dem7++;
			Co3=true;
			}
			if(i%2==0)
			{
			printf("%4d",i);
			dem8++;
			Co3=true;
			}
			if(g%2==0)
			{
			printf("%4d",g);
			dem9++;
			Co3=true;
			}
		}
		if(n>=10000&&n<=99999)
		{
			int m=n%10;
			int o=n/10;
			int p=o%10;
			int q=o/10;
			int r=q%10;
			int s=q/10;
			int t=s%10;
			int u=s/10;
			if(u%2==0)
			{
			printf("%4d",u);
			dem10++;
			Co4=true;
			}
			if(t%2==0)
			{
			printf("%4d",t);
			dem11++;
			Co4=true;
			}
			if(r%2==0)
			{
			printf("%4d",r);
			dem12++;
			Co4=true;
			}
			if(p%2==0)
			{
			printf("%4d",p);
			dem13++;
			Co4=true;
			}
			if(m%2==0)
			{
			printf("%4d",m);
			dem14++;
			Co4=true;
			}
		}
	tinh=dem1+dem2;
	tinh1=dem3+dem4+dem5;
	tinh2=dem6+dem7+dem8+dem9;
	tinh3=dem10+dem11+dem12+dem13+dem14;
	if(Co==true)
		printf("\nSo %d co %d chu so chan",n,dem);
	if(Co1==true)
		printf("\nSo %d co %d chu so chan",n,tinh);
	if(Co2==true)
		printf("\nSo %d co %d chu so chan",n,tinh1);
	if(Co3==true)
		printf("\nSo %d co %d chu so chan",n,tinh2);
	if(Co4==true)
		printf("\nSo %d co %d chu so chan",n,tinh3);
}

void main()
{
	int n,tieptuc;
	quaylai:demchuso(n);
	lietkechuso(n);
	tongcacchuso(n);
	tichcacchuso(n);
	lietkevademcacchusole(n);
	lietkevademcacchusochan(n);
	printf("\nBan co muon tiep tuc chay chuong trinh khong ? Neu co bam phim C,nguoc lai bam bat ky 1 phim nao khac de ket thuc\n");
	tieptuc=getch();
	if(tieptuc=='c'||tieptuc=='C')
		goto quaylai;
}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
Line 17: error: conio.h: No such file or directory
Line 22: error: expected ';', ',' or ')' before '&' token
In function 'lietkevademcacchusole':
Line 196: error: 'false' undeclared (first use in this function)
Line 196: error: (Each undeclared identifier is reported only once
Line 196: error: for each function it appears in.)
Line 208: error: 'true' undeclared (first use in this function)
In function 'lietkevademcacchusochan':
Line 348: error: 'false' undeclared (first use in this function)
Line 360: error: 'true' undeclared (first use in this function)
In function 'main':
Line 496: warning: return type of 'main' is not 'int'


Create a new paste based on this one


Comments: