C++ 程序打印 A 到 Z 之间的字母

编写一个 C++ 程序,在 A 到 Z 之间打印字母,并附带示例。这里,for 循环迭代器 (for(char alpCh = ‘A’; alpCh <= ‘Z’; alpCh++)) 迭代从 A 到 Z 的字符。在 for 循环内部,cout << alpCh << ” “; 语句打印 A 和 Z 之间的字母。

#include<iostream>
using namespace std;

int main()
{
	cout << "\n---List of Alphabets between A and Z are---\n";
	
	for(char alpCh = 'A'; alpCh <= 'Z'; alpCh++)
	{
		cout << alpCh << " ";
	}
	
	return 0;
}
---List of 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 

在此示例中,此 for 循环 (for(alpCh = 65; alpCh <= 90; alpCh++)) 迭代 A (65) 和 Z (90) 的 ASCII 值,而不是从 A 迭代到 Z。

#include<iostream>
using namespace std;

int main()
{
	char alpCh;
	
	cout << "\n---List of Alphabets between A and Z are---\n";
	
	for(alpCh = 65; alpCh <= 90; alpCh++)
	{
		cout << alpCh << " ";
	}
	
	return 0;
}
---List of 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 alpCh = 'A';
	
	cout << "\n---List of Alphabets between A and Z are---\n";
	
	while(alpCh <= 'Z')
	{
		cout << alpCh << " ";
		alpCh++;
	}
	
	return 0;
}
---List of 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 

程序 返回 A 到 Z 之间的字母代码,允许用户输入起始大写字母。接下来,它从 startAlp 打印到 A 的大写字母。

#include<iostream>
using namespace std;

int main()
{
	char alpCh, startAlp;
	
	cout << "\nPlease Enter the Starting Uppercase Alphabet = ";
	cin >> startAlp;
	
	cout << "\n---List of Alphabets between " << startAlp << " and Z are---\n";
	
	for(alpCh = startAlp; alpCh <= 'Z'; alpCh++)
	{
		cout << alpCh << " ";
	}
	
	return 0;
}
Please Enter the Starting Uppercase Alphabet = H

---List of Alphabets between H and Z are---
H I J K L M N O P Q R S T U V W X Y Z 

此返回 A 到 Z 之间字母的示例允许用户输入起始和结束大写字母。接下来,它从 startAlp 打印到 endAlp 的大写字母。

#include<iostream>
using namespace std;

int main()
{
	char alpCh, startAlp, endAlp;
	
	cout << "\nPlease Enter the Starting Uppercase Alphabet = ";
	cin >> startAlp;
	
	cout << "\nPlease Enter the Ending Uppercase Alphabet = ";
	cin >> endAlp;
	
	cout << "\n---List of Alphabets between " << startAlp << " and " << endAlp << " are---\n";
	
	for(alpCh = startAlp; alpCh <= endAlp; alpCh++)
	{
		cout << alpCh << " ";
	}
	
	return 0;
}
CPP Program to Print Alphabets between A and Z