- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- char string[100];
- cout<<"請輸入任意字串(100字內): "<<endl;
- cin.getline(string,100);
- cout<<"字串中每個字元的大小寫依序為: "<<endl;
- for(int i=0; i<=100 && string[i]!=NULL;i++)
- {
- if(int(string[i])>=65 && int(string[i])<=90)
- {
- cout<<"第"<<i+1<<"個字元的ASCII碼為"<<int(string[i])
- <<", 大寫!"<<endl;
- }else if(int(string[i])>=97 && int(string[i])<=122)
- {
- cout<<"第"<<i+1<<"個字元的ASCII碼為"<<int(string[i])
- <<", 小寫!"<<endl;
- }else
- {
- cout<<"第"<<i+1<<"個字元的ASCII碼為"<<int(string[i])
- <<", 非英文字母!"<<endl;
- }
- }
- system("pause");
- return 0;
- }
複製代碼 |