Bài 190 : Hãy liệt kê các giá trị có toàn chữ số lẻ trong mảng một chiều các số nguyên
Tải Code về máy
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
| #include<stdio.h>
#include<conio.h>
#define MAX 100
#define bool
void nhapmang(int a[MAX],int &n)
{
do{
printf("Nhap vao so phan tu cua mang:n=");
scanf("%d",&n);
if(n<1||n>MAX)
printf("So ban nhap vao khong hop le!Xin vui long nhap lai!\n");
else
break;
}while(n<1||n>MAX);
for(int i=0;i<n;i++)
{
printf("Nhap vao a[%d]=",i);
scanf("%d",&a[i]);
}
}
void xuatmang(int a[MAX],int n)
{
printf("\n>>>>>>>>>>>>MANG VUA NHAP LA:<<<<<<<<<<<<<<<\n");
for(int i=0;i<n;i++)
{
printf("%4d",a[i]);
}
printf("\n");
}
void lietke(int a[MAX],int n)
{
int Co;
bool Co=false;
int dem,demb=0,demc=0,deme=0,demj=0,demo=0;
printf("Cac gia tri co toan chu so le la:");
for(int i=0;i<n;i++)
{
if(a[i]>=-9&&a[i]<=9)
{
int b=a[i]%10;
if(b%2!=0)
{
printf("%4d",a[i]);
demb++;
Co=true;
}
}
if(a[i]>=-99&&a[i]<=-10||a[i]>=10&&a[i]<=99)
{
int c=a[i]/10;
int d=a[i]%10;
if(c%2!=0&&d%2!=0)
{
printf("%4d",a[i]);
demc++;
Co=true;
}
}
if(a[i]>=-999&&a[i]<=-100||a[i]>=100&&a[i]<=999)
{
int e=a[i]/100;
int f=a[i]/10;
int g=a[i]%10;
if(e%2!=0&&f%2!=0&&g%2!=0)
{
printf("%4d",a[i]);
deme++;
Co=true;
}
}
if(a[i]>=-9999&&a[i]<=-1000||a[i]>=1000&&a[i]<=9999)
{
int j=a[i]/1000;
int k=a[i]/100;
int l=a[i]/10;
int m=a[i]%10;
if(j%2!=0&&k%2!=0&&l%2!=0&&m%2!=0)
{
printf("%4d",a[i]);
demj++;
Co=true;
}
}
if(a[i]>=-99999&&a[i]<=-10000||a[i]>=10000&&a[i]<=99999)
{
int o=a[i]/10000;
int p=a[i]/1000;
int q=a[i]/100;
int r=a[i]/10;
int s=a[i]%10;
if(o%2!=0&&p%2!=0&&q%2!=0&&r%2!=0&&s%2!=0)
{
printf("%4d",a[i]);
demo++;
Co=true;
}
}
}
dem=demb+demc+deme+demj+demo;
if(Co==true)
printf("\nTrong mang co %d gia tri thoa man yeu cau de bai",dem);
else
printf("\nKhong co gia tri nao trong mang thoa man yeu cau de bai");
}
void main()
{
int a[MAX],n,NAMSON;
quaylai:nhapmang(a,n);
xuatmang(a,n);
lietke(a,n);
printf("\nBan co muon tiep tuc chay chuong trinh khong ? Neu co bam phim C,nguoc lai bam bat ky phim nao khac de ket thuc\n");
NAMSON=getch();
if(NAMSON=='c'||NAMSON=='C')
goto quaylai;
}
|
Nhận xét
Đăng nhận xét