Sponsored Ad

Saturday, March 12, 2011

How to Print a String Triangle using C#

This is simple program. The student get as there first lab assignment. Just writing here to help them and understand the programming logic.

How to Print a String Triangle using C#

using System;

namespace MyApp
{
    class string_triangle_class
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter a string:");
            string str = Console.ReadLine();

            for (int j = 0; j < str.Length; j++ )
            {
                for (int i = 0; i <= j; i++ )
                    Console.Write(str[i]);
                Console.WriteLine("");
            }

            Console.ReadLine();
        }
    }
}

No comments:

Post a Comment

Sponsored Ad

Development Updates