Bai tap chuong 1.pdf

# Bai tap chuong 1.pdf - Bài tập chương 1 Bài 1 Cho...

• 6

This preview shows page 1 - 3 out of 6 pages.

Bài t p ch ươ ng 1 Bài 1. Cho m t m ng a có n s nguyên, hãy ki m tra các ñ i u ki n sau: + M ng có s p th t t ă ng hay không? (Áp d ng thu t toán ñế m v i di u ki n ñế m là a[i]<=a[i+1]) + M ng có s p th t gi m hay không? + M ng có s p th t hay không? (D a vào k ế t qu c a hai câu h i trên) Bài 2. Đế m các s không âm trong m ng a có n s nguyên int dem_khong_am ( int *a, int n) { int i,kq=0; for (i = 0 ; i < n ; i++) if (a[i] >= 0) kq++; return kq; } Bài 3. Đế m các s nguyên t trong m ng a có n s nguyên int dem_nguyen_to ( int *a, int n) { int i,kq=0; for (i = 0 ; i < n ; i++) if (nguyen_to(a[i])) kq++; retrurn kq; } Bài 4. Đế m s l n xu t hi n c a ph n t x trong m ng a. int count (int x, int *a, int n) { int i,kq=0; for (i = 0 ; i < n ; i++) if (a[i]==x) kq++; return kq; } Bài 5. Tìm s âm l n nh t trong m ng a. int tim_so_am (int *a, int n, int &x) { int i,kq = 0; for (i = 0 ;i < n && kq= = 0 ; i++) if (a[i] < 0) { x = a[i]; kq = i; } return kq; }

Subscribe to view the full document.

void max_am (int *a, int n) { int i, x, max; if (tim_so_am(a,n,x) { max=x; for (i=0 ; i < n ; i++) if (max < a[i] && a[i] < 0) max = a[i]; printf("\nSo can tim la %d : ",max); } else printf("\nMang nay khong co so am."); } Bài 6. Tìm ph n t có s l n xu t hi n nhi
• Spring '12
• NguyenXuanLong,JohnLafferty

{[ snackBarMessage ]}

###### "Before using Course Hero my grade was at 78%. By the end of the semester my grade was at 90%. I could not have done it without all the class material I found."
— Christopher R., University of Rhode Island '15, Course Hero Intern

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern