Bài 2 lập trình C K65

#include<stdio.h> int n; // bien toan cuc void nhap(float a[]) { for(int i=0; i<n; i++) { printf("nhap vao so thu %d: ", i+1); scanf("%f",&a[i]); } } void xuat(float a[]) { for(int i=0; i<n; i++) printf("%.2f ",a[i]); } void sapxep(float a[]) { float tg; for(int i=0; i<n; i++) for(int j=n-1; j>i; j--) if(a[i]>a[j]) { tg=a[i]; a[i]=a[j]; a[j]=tg; } } void max_min(float a[]) { int i; float max, min; max=a[0]; for(i=1; i<n; i++) if(a[i]>max) max=a[i]; min=a[0]; for(i=0; i<n; i++) if(a[i]<min) min=a[i]; printf("so lon nhat cua day la %.2f\nso nho nhat cua day la %.2f",max,min); } void nguyento(float a[]) { int i,j,dem=0; int b[100]; for(i=0; i<n; i++) { b[i]= (int) a[i]; for(j=1; j<=b[i]; j++) if(b[i]%j==0) dem++; if(dem==2) printf("%.2f\n",a[i]); dem=0; } } main() { float a[100]; do { printf("nhap vao kich thuoc n cua day (n nho hon 100): "); scanf("%d",&n); if(n>=100) printf("o tao bao nhap nho hon 100 ma! nhap lai ngay!\n"); } while(n>=100); nhap(a); printf("day ban vua nhap la: \n"); xuat(a); printf("\n"); sapxep(a); printf("day sap xep theo chieu khong giam la: \n"); xuat(a); printf("\n"); max_min(a); printf("\n"); printf("danh sach cac so trong day co phan nguyen la mot so nguyen to la: \n"); nguyento(a); }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.