返回列表 發帖

021 while 迴圈拆解文字

宣告一個字元陣列,然後拆解每個字顯示在新列上。

  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <string.h>
  4. using namespace std;
  5. int main()
  6. {
  7.         int i = 0;
  8.         char a[] = "ABCD";
  9.         while ( i < strlen(a))
  10.         {
  11.                 cout << a [i] << endl;
  12.                 i++;
  13.         }
  14.         system ("pause");
  15.         return 0;
  16. }
複製代碼

TOP

  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <string.h>
  4. using namespace std;
  5. int main()
  6. {
  7.         char a[] = "abc";
  8.         int i;
  9.         while(i < strlen(a))
  10.         {
  11.                 cout << a[i] << endl;
  12.                 i++;
  13.         }
  14.         system("pause");
  15.         return 0;
  16. }
複製代碼

TOP

返回列表