📌  相关文章
📜  程序以大写和小写形式显示从 A 到 Z 的所有字母

📅  最后修改于: 2022-05-13 01:57:59.222000             🧑  作者: Mango

程序以大写和小写形式显示从 A 到 Z 的所有字母

可以使用两种方法打印小写和大写字母,第一种是使用 ASCII 值,第二种是使用循环直接打印从 'A' 到 'Z' 的值。下面是这两种方法的实现:

  • 使用 ASCII 值:
    • 大写字母的 ASCII 值 – 65 到 90。
    • 小写字母的 ASCII 值 - 97 到 122。
    C++
    // C++ program to print alphabets
    #include 
    using namespace std;
      
    // Function to print the alphabet
    // in lower case
    void lowercaseAlphabets()
    {
        // lowercase
      
        for (int c = 97; c <= 122; ++c)
            cout << c << " ";
      
        cout << endl;
    }
    // Function to print the alphabet
    // in upper case
    void uppercaseAlphabets()
    {
      
        // uppercase
        for (int c = 65; c <= 90; ++c)
            cout << c << " ";
      
        cout << endl;
    }
      
    // Driver code
    int main()
    {
      
        cout << "Uppercase Alphabets" << endl;
        uppercaseAlphabets(ch);
      
        cout << "Lowercase Alphabets " << endl;
        lowercaseAlphabets(ch);
      
        return 0;
    }


    C
    // C program to print alphabets
    #include 
      
    // Function to print the alphabet
    // in lower case
    void lowercaseAlphabets()
    {
        // for lowercase
        for (int c = 97; c <= 122; ++c)
            printf("%c ", c);
        printf("\n");
    }
    // Function to print the alphabet
    // in upper case
    void uppercaseAlphabets()
    {
      
        // Run a loop from 65 to 90
        for (int c = 65; c <= 90; ++c)
      
            // print its ascii values
            printf("%c ", c);
      
        printf("\n");
    }
      
    // Driver program
    int main()
    {
      
        printf("Uppercase Alphabets\n");
        uppercaseAlphabets();
      
        printf("Lowercase Alphabets\n");
        lowercaseAlphabets();
      
        return 0;
    }


    Java
    // JAVA program to print alphabet
    class Alpha {
        private int ch;
      
        void uppercaseAlphabets()
        {
      
            // uppercase
            for (int c = 65; c <= 90; ++c)
                System.out.print(" " + c);
      
            System.out.print("\n");
        }
        void lowercaseAlphabets()
        {
      
            // lowercase
            for (int c = 97; c <= 122; ++c)
                System.out.print(" " + c);
      
            System.out.print("\n");
        }
      
        // Driver program
        public static void main(String[] args)
        {
            int ch;
            System.out.println("Uppercase Alphabets");
            Alpha ob = new Alpha();
            ob.uppercaseAlphabets();
      
            System.out.println("Lowercase Alphabets ");
            ob.lowercaseAlphabets();
        }
    }


    Python3
    # Python3 program to print alphabets
      
    # Function to print the alphabet
    # in lower case
    def lowercaseAlphabets():
      
        # lowercase
        for c in range(97, 123):
            print(chr(c), end = " ");
      
        print("");
      
    # Function to print the alphabet
    # in upper case
    def uppercaseAlphabets():
      
        # uppercase
        for c in range(65, 91):
            print(chr(c), end = " ");
      
        print("");
      
    # Driver code
    print("Uppercase Alphabets");
    uppercaseAlphabets();
      
    print("Lowercase Alphabets ");
    lowercaseAlphabets();
      
    # This code is contributed by mits


    C#
    // C# program to print alphabet
      
    using System;
    class Alpha {
        private int ch;
      
        void uppercaseAlphabets()
        {
      
            // uppercase
            for (int c = 65; c <= 90; ++c)
                Console.Write(" " + (char)c);
      
            Console.Write("\n");
        }
        void lowercaseAlphabets()
        {
      
            // lowercase
            for (int c = 97; c <= 122; ++c)
                Console.Write(" " + (char)c);
      
            Console.Write("\n");
        }
      
        // Driver program
        public static void Main()
        {
            int ch;
            Console.WriteLine("Uppercase Alphabets");
            Alpha ob = new Alpha();
            ob.uppercaseAlphabets();
      
            Console.WriteLine("Lowercase Alphabets ");
            ob.lowercaseAlphabets();
        }
    }


    PHP


    C++
    // C++ program to print alphabets
    #include 
    using namespace std;
      
    // Function to print the alphabet
    // in lower case
    void lowercaseAlphabets()
    {
        // lowercase
      
        for (char c = 'a'; c <= 'z'; ++c)
            cout << c << " ";
      
        cout << endl;
    }
    // Function to print the alphabet
    // in upper case
    void uppercaseAlphabets()
    {
      
        // uppercase
        for (char c = 'A'; c <= 'Z'; ++c)
            cout << c << " ";
      
        cout << endl;
    }
      
    // Driver code
    int main()
    {
      
        cout << "Uppercase Alphabets" << endl;
        uppercaseAlphabets(ch);
      
        cout << "Lowercase Alphabets " << endl;
        lowercaseAlphabets(ch);
      
        return 0;
    }


    C
    // C program to print alphabets
    #include 
      
    // Function to print the alphabet
    // in lower case
    void lowercaseAlphabets()
    {
        // for lowercase
        for (char c = 'a'; c <= 'z'; ++c)
            printf("%c ", c);
        printf("\n");
    }
    // Function to print the alphabet
    // in upper case
    void uppercaseAlphabets()
    {
      
        // Run a loop from 65 to 90
        for (char c = 'A'; c <= 'Z'; ++c)
      
            // print its ascii values
            printf("%c ", c);
      
        printf("\n");
    }
      
    // Driver program
    int main()
    {
      
        printf("Uppercase Alphabets\n");
        uppercaseAlphabets();
      
        printf("Lowercase Alphabets\n");
        lowercaseAlphabets();
      
        return 0;
    }


    Java
    // Java program to print alphabet
    class Alpha {
        private int ch;
      
        void uppercaseAlphabets()
        {
      
            // uppercase
            for (char c = 'A'; c <= 'Z'; ++c)
                System.out.print(" " + c);
      
            System.out.print("\n");
        }
        void lowercaseAlphabets()
        {
      
            // lowercase
            for (char c = 'a'; c <= 'z'; ++c)
                System.out.print(" " + c);
      
            System.out.print("\n");
        }
      
        // Driver program
        public static void main(String[] args)
        {
      
            System.out.println("Uppercase Alphabets");
            Alpha ob = new Alpha();
            ob.uppercaseAlphabets();
      
            System.out.println("Lowercase Alphabets ");
            ob.lowercaseAlphabets();
        }
    }


    C#
    // C# program to print alphabet
    using System;
      
    public class Alpha {
        private int ch;
      
        // Function to print the alphabet
        // in upper case
        void uppercaseAlphabets()
        {
      
            // uppercase
            for (char c = 'A'; c <= 'Z'; ++c)
                Console.Write(" " + c);
      
            Console.Write("\n");
        }
      
        // Function to print the alphabet
        // in lower case
        void lowercaseAlphabets()
        {
      
            // lowercase
            for (char c = 'a'; c <= 'z'; ++c)
                Console.Write(" " + c);
      
            Console.Write("\n");
        }
      
        // Driver code
        public static void Main()
        {
            Console.WriteLine("Uppercase Alphabets");
            Alpha ob = new Alpha();
            ob.uppercaseAlphabets();
      
            Console.WriteLine("Lowercase Alphabets ");
            ob.lowercaseAlphabets();
        }
    }
      
    // This code is contributed by Rajput-Ji


    PHP


    输出:
    Uppercase Alphabets
    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 
    Lowercase Alphabets
    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' 的循环
    • 对于大写字符- 运行从 'A' 到 'Z' 的循环

    C++

    // C++ program to print alphabets
    #include 
    using namespace std;
      
    // Function to print the alphabet
    // in lower case
    void lowercaseAlphabets()
    {
        // lowercase
      
        for (char c = 'a'; c <= 'z'; ++c)
            cout << c << " ";
      
        cout << endl;
    }
    // Function to print the alphabet
    // in upper case
    void uppercaseAlphabets()
    {
      
        // uppercase
        for (char c = 'A'; c <= 'Z'; ++c)
            cout << c << " ";
      
        cout << endl;
    }
      
    // Driver code
    int main()
    {
      
        cout << "Uppercase Alphabets" << endl;
        uppercaseAlphabets(ch);
      
        cout << "Lowercase Alphabets " << endl;
        lowercaseAlphabets(ch);
      
        return 0;
    }
    

    C

    // C program to print alphabets
    #include 
      
    // Function to print the alphabet
    // in lower case
    void lowercaseAlphabets()
    {
        // for lowercase
        for (char c = 'a'; c <= 'z'; ++c)
            printf("%c ", c);
        printf("\n");
    }
    // Function to print the alphabet
    // in upper case
    void uppercaseAlphabets()
    {
      
        // Run a loop from 65 to 90
        for (char c = 'A'; c <= 'Z'; ++c)
      
            // print its ascii values
            printf("%c ", c);
      
        printf("\n");
    }
      
    // Driver program
    int main()
    {
      
        printf("Uppercase Alphabets\n");
        uppercaseAlphabets();
      
        printf("Lowercase Alphabets\n");
        lowercaseAlphabets();
      
        return 0;
    }
    

    Java

    // Java program to print alphabet
    class Alpha {
        private int ch;
      
        void uppercaseAlphabets()
        {
      
            // uppercase
            for (char c = 'A'; c <= 'Z'; ++c)
                System.out.print(" " + c);
      
            System.out.print("\n");
        }
        void lowercaseAlphabets()
        {
      
            // lowercase
            for (char c = 'a'; c <= 'z'; ++c)
                System.out.print(" " + c);
      
            System.out.print("\n");
        }
      
        // Driver program
        public static void main(String[] args)
        {
      
            System.out.println("Uppercase Alphabets");
            Alpha ob = new Alpha();
            ob.uppercaseAlphabets();
      
            System.out.println("Lowercase Alphabets ");
            ob.lowercaseAlphabets();
        }
    }
    

    C#

    // C# program to print alphabet
    using System;
      
    public class Alpha {
        private int ch;
      
        // Function to print the alphabet
        // in upper case
        void uppercaseAlphabets()
        {
      
            // uppercase
            for (char c = 'A'; c <= 'Z'; ++c)
                Console.Write(" " + c);
      
            Console.Write("\n");
        }
      
        // Function to print the alphabet
        // in lower case
        void lowercaseAlphabets()
        {
      
            // lowercase
            for (char c = 'a'; c <= 'z'; ++c)
                Console.Write(" " + c);
      
            Console.Write("\n");
        }
      
        // Driver code
        public static void Main()
        {
            Console.WriteLine("Uppercase Alphabets");
            Alpha ob = new Alpha();
            ob.uppercaseAlphabets();
      
            Console.WriteLine("Lowercase Alphabets ");
            ob.lowercaseAlphabets();
        }
    }
      
    // This code is contributed by Rajput-Ji
    

    PHP

    输出:
    Uppercase Alphabets
    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 
    Lowercase Alphabets
    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 
    

这些程序连续打印大写和小写的所有字母。