當前位置:編程學習大全網 - 編程軟體 - 用c++編程,用switch編小寫輸入大寫輸入的程序。還有輸入壹段長的字符,記錄其中大寫,小寫,數字的個數

用c++編程,用switch編小寫輸入大寫輸入的程序。還有輸入壹段長的字符,記錄其中大寫,小寫,數字的個數

妳好!!

第壹個程序,小寫轉換成大寫:

完整的代碼:

#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');

else

cout<<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;

}

  • 上一篇:手鏈上中國結開了
  • 下一篇:我51不回家,{我是大學生}想在南昌在份工作,希望大家幫忙說壹下,那裏可以找到工作>>>
  • copyright 2024編程學習大全網