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

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; }
Image of page 1

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
Image of page 2
Image of page 3
  • Spring '12
  • NguyenXuanLong,JohnLafferty

{[ snackBarMessage ]}

Get FREE access by uploading your study materials

Upload your study materials now and get free access to over 25 million documents.

Upload now for FREE access Or pay now for instant access
Christopher Reinemann
"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

Ask a question for free

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern