立即學習:https://edu.csdn.net/course/play/10534/378125?utm_source=blogtoedu
學習目標:
1. char類型是什麼?
2. char的基本用途。
示例代碼1:
#include <stdio.h>
int main() {
char x = '\0';
int diff = 'a' - 'A';
printf("please input a char: ");
scanf("%c", &x);
if (x >= 'A' && x <= 'Z') {
printf("%c\n", x + diff);
} else if (x >= 'a' && x <= 'z') {
printf("%c\n", x - diff);
} else {
printf("%c\n", x);
}
return 0;
}
實例代碼2:
#include <stdio.h>
int main() {
unsigned int score = 0;
char grade = '\0';
printf("please input your score: ");
scanf("%d", &score);
if (score >= 90) {
grade = 'A';
} else if (score >= 60) {
grade = 'B';
} else {
grade = 'C';
}
printf("%c\n", grade);
return 0;
}