📜  程序使用循环从A到Z打印字母

📅  最后修改于: 2021-05-28 04:18:59             🧑  作者: Mango

任务是使用循环将字母从A打印到Z。

在下面的程序中,使用for循环将字母从A到Z进行打印。采用循环变量来执行’char’类型的操作。循环变量“ i”用第一个字母“ A”初始化,并在每次迭代时加1。在循环中,此字符“ i”被打印为字母。

程序:

C++
// C++ program to find the print
// Alphabets from A to Z
#include 
using namespace std;
  
int main()
{
    // Declare the variables
    char i;
  
    // Display the alphabets
    cout << "The Alphabets from A to Z are: \n";
  
    // Traverse each character
    // with the help of for loop
    for (i = 'A'; i <= 'Z'; i++)
    {
  
        // Print the alphabet
        cout << i <<" ";
    }
  
    return 0;
}
  
// This code is contributed by
// Shubhamsingh10


C
// C program to find the print
// Alphabets from A to Z
  
#include 
  
int main()
{
    // Declare the variables
    char i;
  
    // Display the alphabets
    printf("The Alphabets from A to Z are: \n");
  
    // Traverse each character
    // with the help of for loop
    for (i = 'A'; i <= 'Z'; i++) {
  
        // Print the alphabet
        printf("%c ", i);
    }
  
    return 0;
}


Java
// Java program to find the print
// Alphabets from A to Z
class GFG
{
  
    public static void main(String[] args) 
    {
        // Declare the variables
        char i;
  
        // Display the alphabets
        System.out.printf("The Alphabets from A to Z are: \n");
  
        // Traverse each character
        // with the help of for loop
        for (i = 'A'; i <= 'Z'; i++)
        {
  
            // Print the alphabet
            System.out.printf("%c ", i);
        }
  
    }
}
  
/* This code contributed by PrinciRaj1992 */


Python3
# Python3 program to find the print
# Alphabets from A to Z
  
if __name__ == '__main__':
      
    # Declare the variables
    i = chr;
  
    # Display the alphabets
    print("The Alphabets from A to Z are: ");
  
    # Traverse each character
    # with the help of for loop
    for i in range(ord('A'), ord('Z') + 1):
  
        # Print the alphabet
        print(chr(i), end=" ");
          
# This code is contributed by Rajput-Ji


C#
// C# program to find the print
// Alphabets from A to Z
using System;
  
class GFG
{
  
    public static void Main(String[] args) 
    {
        // Declare the variables
        char i;
  
        // Display the alphabets
        Console.Write("The Alphabets from A to Z are: \n");
  
        // Traverse each character
        // with the help of for loop
        for (i = 'A'; i <= 'Z'; i++)
        {
  
            // Print the alphabet
            Console.Write("{0} ", i);
        }
  
    }
}
  
// This code is contributed by Rajput-Ji


输出:

The Alphabets from A to 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的C基础课程》。