gpt-3.5-turbo-0613· openai
Suzhen/CodeChat
Viết code đếm số ký tự alphabet ngôn ngữ C
- User
Viết code đếm số ký tự alphabet ngôn ngữ C
- Assistant
Dưới đây là một ví dụ về cách viết code để đếm số ký tự alphabet trong ngôn ngữ C:
c#include <stdio.h> #include <ctype.h> int main() { char str[100]; int count = 0; printf("Nhập một chuỗi: "); fgets(str, sizeof(str), stdin); for (int i = 0; str[i] != '\0'; i++) { if (isalpha(str[i])) { count++; } } printf("Số ký tự alphabet: %d\n", count); return 0; }Ở đây, chúng ta sử dụng hàm
isalpha()từ thư việnctype.hđể kiểm tra xem mỗi ký tự có phải là một chữ cái không. Nếu ký tự đó là một chữ cái, chúng ta tăng biếncountlên 1. Cuối cùng, chúng ta in ra số ký tự alphabet đã đếm được.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.