Yêu cầu
XÂY DỰNG CHƯƠNG TRÌNH ĐĂNG NHẬP BẰNG USERNAME VÀ PASSWORD- Input: Nhập vào username và password
- Output: Đăng nhập thành công hay không thành công
Hướng dẫn giải
Codecpp
1/*2BÀI 2: XÂY DỰNG CHƯƠNG TRÌNH ĐĂNG NHẬP BẰNG USERNAME VÀ PASSWORD3 4Input: Nhập vào username và password5Output: Đăng nhập thành công hay không thành công6Biết rằng:7 username phải bằng "admin"8 password phải bằng "123"9*/10#include<stdio.h>11#include<conio.h>12#include<string.h>13 14int main() {15 // 1. Khoi tao mang 1 chieu 50 phan tu16 char username[50];17 char password[50];18 19 // 2. INPUT nhập liệu20 printf("Moi ban nhap username: ");21 gets(username);22 23 printf("Moi ban nhap password: ");24 gets(password);25 26 // 3. OUTPUT xuất ra màn hình27 printf("=== CHUONG TRINH DANG NHAP BANG USERNAME VA PASSWORD ===\n");28 printf("Thong tin:\n");29 printf("- Username vua nhap la: %s\n", username);30 printf("- Password vua nhap la: %s\n", password);31 32 // 4. Kiem tra33 // Neu username == "admin" VA password == "123"34 // -> Dang nhap thanh cong.35 // Neu khong:36 // -> Dang nhap that bai.37 int ss1 = strcmp(username, "admin");38 int ss2 = strcmp(password, "123");39 40 // 5. In ra man hinh ket qua41 if(ss1 == 0 && ss2 == 0) {42 printf("Dang nhap thanh cong!");43 } else {44 printf("Dang nhap that bai!");45 }46 47 getch(); // Lenh dung man hinh48 return 0;49}
