//Bai 1 #include #include #include int main(){ char s[100]; printf("Xin moi nhap vao chuoi: "); gets(s); int i = 0; int n = 0; // bien de dem so nguyen am int p = 0; // bien de dem so phu am char nguyenAm[] = {'a','i','e','o','u'}; //dung mang de tim nguyen am //bug: ko dem dc chu in hoa //Khi gia tri cuoi cung cua mang != null while(s[i++] != '\0') { //di xuong dong 21 neu s[i] la nguyen am, && doan mach nen n++ ko tang them for(int j = 0; j < 5; j++) if(s[i] == nguyenAm[j] && n++) goto cnt; //loai bo ky tu bang ASCII if(s[i] > 64) p++; cnt:; } printf("Chuoi '%s' co chua: %d nguyen am va %d phu am.", s, n, p); getch(); return 0; } //Bai 2 #include #include #include int main(){ char userSys[] = "admin", user[100]; int passSys = 12345, pass; printf("\nHay nhap vao ten dang nhap: "); gets(user); fflush(stdin); printf("\nHay nhap vao mat khau: ");scanf("%i", &pass); //kiem tra xem username vs password co giong voi tren userSys if(!strcmp(user,userSys) && pass == passSys) printf("\nDang nhap thanh cong!"); else printf("\nThong tin hoac mat khau ban nhap vao khong khop!"); getch(); return 0; } //bai sap xep chuoi #include #include #include int main(){ char s[5][20]; //mang chuoi int i, j; for (i = 0; i < 5; i++) { printf("\nHay nhap vao chuoi %i: ", i+1); fflush(stdin); gets(s[i]); } //Chay giai thuat sap xep for (i = 1; i < 5; i++) { for (j = 1; j < 5; j++) { //bien chu thanh chu thuong roi moi so sanh if (strcmp(strlwr(s[j - 1]), strlwr(s[j])) > 0){ char temp[20]; strcpy(temp, s[j-1]); strcpy(s[j-1], s[j]); strcpy(s[j], temp); } } } i = 0; while(i < 5){ printf("\n%s",s[i++]); } return 0; }