编写一个 C++ 程序,通过示例打印从 a 到 z 的字母。此处,for 循环 (for(char lwalpCh = ‘a’; lwalpCh <= ‘z’; lwalpCh++) ) 迭代从 a 到 z 的字符。在循环内,cout << lwalpCh << ” “; 语句打印从 a 到 z 的字符。
#include<iostream>
using namespace std;
int main()
{
cout << "\n---List of Lowercase Alphabets between a and z are---\n";
for(char lwalpCh = 'a'; lwalpCh <= 'z'; lwalpCh++)
{
cout << lwalpCh << " ";
}
return 0;
}

在此代码中,此 for 循环 (for(lwalpCh = 97; lwalpCh <= 122; lwalpCh++)) 迭代 a 和 z 的 ASCII 值,而不是在 a 和 z 之间迭代。
#include<iostream>
using namespace std;
int main()
{
char lwalpCh;
cout << "\n---List of Lowercase Alphabets between a and z are---\n";
for(lwalpCh = 97; lwalpCh <= 122; lwalpCh++)
{
cout << lwalpCh << " ";
}
return 0;
}
---List of Lowercase Alphabets between a and z are---
a b c d e f g h i j k l m n o p q r s t u v w x y z
使用 while 循环打印从 a 到 z 的字母的 C++ 程序
#include<iostream>
using namespace std;
int main()
{
char lwalpCh = 'a';
cout << "\n---List of Lowercase Alphabets between a and z are---\n";
while(lwalpCh <= 'z')
{
cout << lwalpCh << " ";
lwalpCh++;
}
return 0;
}
---List of Lowercase Alphabets between a and z are---
a b c d e f g h i j k l m n o p q r s t u v w x y z
此 C++ 程序返回从 a 到 z 的字母代码允许用户输入起始小写字母。接下来,它打印从 startLwAlp 到 z 的小写字母。
#include<iostream>
using namespace std;
int main()
{
char startLwAlp;
cout << "\nPlease Enter the Starting Lowercase Alphabet = ";
cin >> startLwAlp;
cout << "\n---List of Lowercase between " << startLwAlp << " and z are---\n";
for(char lwalpCh = startLwAlp; lwalpCh <= 'z'; lwalpCh++)
{
cout << lwalpCh << " ";
}
return 0;
}
Please Enter the Starting Lowercase Alphabet = j
---List of Lowercase between j and z are---
j k l m n o p q r s t u v w x y z
此返回从 a 到 z 的字母的代码允许用户输入起始和结束小写字母。接下来,它打印从 startLwAlp 到 endLwAlp 的小写字母。
#include<iostream>
using namespace std;
int main()
{
char startLwAlp, endLwAlp;
cout << "\nPlease Enter the Starting Lowercase Alphabet = ";
cin >> startLwAlp;
cout << "\nPlease Enter the Starting Lowercase Alphabet = ";
cin >> endLwAlp;
cout << "\n---List of Lowercase between " << startLwAlp << " and " << endLwAlp << " are---\n";
for(char lwalpCh = startLwAlp; lwalpCh <= endLwAlp; lwalpCh++)
{
cout << lwalpCh << " ";
}
return 0;
}
Please Enter the Starting Lowercase Alphabet = f
Please Enter the Starting Lowercase Alphabet = v
---List of Lowercase between f and v are---
f g h i j k l m n o p q r s t u v