妳好!!
第壹個程序,小寫轉換成大寫:完整的代碼:
#include?<iostream>using?namespace?std;
int?main()
{
char?str[100];? cin.getline(str,100); int?i=0; while(str[i]!='\0') { if((str[i]?>=?'a')&&(str[i]?<=?'z'))?//判斷是否是小寫cout<<char(str[i]+'A'-'a');
elsecout<<str[i];
i++;?//下標後移,取下壹字母 } return?0;}
第二個程序,統計大小寫和數字個數完整的代碼:
#include?<iostream>using?namespace?std;
int?main()
{
char?str[100];? int?a=0,b=0,c=0;? cin.getline(str,100); int?i=0; while(str[i]!='\0') { if((str[i]?>=?'a')&&(str[i]?<=?'z'))?//判斷是否是小寫a++;
if((str[i]?>=?'A')&&(str[i]?<=?'Z'))?//判斷是否是大寫b++;
if((str[i]?>=?'0')&&(str[i]?<=?'9'))?//判斷是否是數字?c++;
i++;?//下標後移,取下壹字母 } cout?<<?"小寫個數"?<<?a?<<?endl;? cout?<<?"大寫個數"?<<?b?<<?endl;? cout?<<?"數字個數"?<<?c?<<?endl;? return?0;}