Anachronos

Untitled

Jul 1st, 2021 (edited)
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.85 KB | None | 0 0
  1. //Bai 1
  2. #include <stdio.h>
  3. #include <conio.h>
  4. #include <string.h>
  5.  
  6. int main(){
  7.     char s[100];
  8.     printf("Xin moi nhap vao chuoi: ");
  9.     gets(s);
  10.     int i = 0;
  11.     int n = 0; // bien de dem so nguyen am
  12.     int p = 0; // bien de dem so phu am
  13.     char nguyenAm[] = {'a','i','e','o','u'}; //dung mang de tim nguyen am
  14.     //bug: ko dem dc chu in hoa
  15.     //Khi gia tri cuoi cung cua mang != null
  16.     while(s[i++] != '\0') {
  17.         //di xuong dong 21 neu s[i] la nguyen am, && doan mach nen n++ ko tang them
  18.         for(int j = 0; j < 5; j++) if(s[i] == nguyenAm[j] && n++) goto cnt;
  19.         //loai bo ky tu bang ASCII
  20.         if(s[i] > 64) p++;
  21.         cnt:;
  22.     }
  23.    
  24.     printf("Chuoi '%s' co chua: %d nguyen am va %d phu am.", s, n, p);
  25.     getch();
  26.     return 0;
  27. }
  28.  
  29.  
  30. //Bai 2
  31. #include <stdio.h>
  32. #include <conio.h>
  33. #include <string.h>
  34.  
  35. int main(){
  36.     char userSys[] = "admin", user[100];
  37.     int passSys = 12345, pass;
  38.    
  39.     printf("\nHay nhap vao ten dang nhap: ");
  40.     gets(user); fflush(stdin);
  41.     printf("\nHay nhap vao mat khau: ");scanf("%i", &pass);
  42.    
  43.     //kiem tra xem username vs password co giong voi tren userSys
  44.     if(!strcmp(user,userSys) && pass == passSys) printf("\nDang nhap thanh cong!");
  45.     else printf("\nThong tin hoac mat khau ban nhap vao khong khop!");
  46.     getch();
  47.     return 0;
  48. }
  49.  
  50. //bai sap xep chuoi
  51. #include <stdio.h>
  52. #include <conio.h>
  53. #include <string.h>
  54.  
  55. int main(){
  56.     char s[5][20]; //mang chuoi
  57.     int i, j;
  58.    
  59.    
  60.     for (i = 0; i < 5; i++) {
  61.         printf("\nHay nhap vao chuoi %i: ", i+1);
  62.         fflush(stdin); 
  63.         gets(s[i]);
  64.     }
  65.     //Chay giai thuat sap xep
  66.     for (i = 1; i < 5; i++) {
  67.         for (j = 1; j < 5; j++) {
  68.             //bien chu thanh chu thuong roi moi so sanh
  69.             if (strcmp(strlwr(s[j - 1]), strlwr(s[j])) > 0){
  70.             char temp[20];
  71.             strcpy(temp, s[j-1]);
  72.             strcpy(s[j-1], s[j]);
  73.             strcpy(s[j], temp);
  74.             }
  75.         }
  76.     }
  77.     i = 0;
  78.     while(i < 5){
  79.         printf("\n%s",s[i++]);
  80.     }
  81.     return 0;
  82. }
Add Comment
Please, Sign In to add comment