.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Post New Resource Bookmark and Share   

Given string will display in diamond shape

Posted By:laptop charles       Posted Date: September 03, 2010    Points: 10    Category:    URL: http://www.dotnetspark.com  

Diamond shape.
 

It has used String remove method....
using System;
using System.Collections.Generic;
using System.Text;

namespace Given_particular_string_diamand
{
    class Program
    {
        static void Main(string[] args)
        {
            string c ;
            int a=40;
            Console.WriteLine("Enter the String");
            c=Console.ReadLine();

                for (int i = c.Length; i >= 0; i--)
                {
                    for (int j = 1; j <= a; j=j+2)
                    {
                        Console.Write(" ");
                       
                    }
                    Console.WriteLine(c.Remove(0, i));
                    a--;
                }
            for (int i = 1; i <=c.Length; i++)
            {
                for (int j = a+1; j >=1; j = j - 2)
                {
                    Console.Write(" ");

                }
                a++;
                Console.WriteLine(c.Remove(0, i));
            }

            Console.ReadLine();
        }
    }
}

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend