31 July 2011

Reverse of a string or number in console apps


class Reverseofno
    {
        public static void Main()
        {
            Console.WriteLine("enter a no/string: ");
            string a = Console.ReadLine();
            for (int x = a.Length - 1; x >= 0; x--)
            {
                Console.Write(a[x]);
            }

            Console.WriteLine();
           
            string bb = string.Empty;
            Console.WriteLine("enter a no/string: ");
            string b = Console.ReadLine();
            for (int x = b.Length - 1; x >= 0; x--)
            {
                bb += b[x].ToString();
            }
            string[] bbb = new string[bb.Split(' ').Length];
            for (int y = 0; y <= bb.Split(' ').Length-1; y++)
            {
                bbb[y] = bb.Split(' ')[y]+" ";
            }
            for (int z = bbb.Length - 1; z >= 0; z--)
            {
                Console.Write(bbb[z]);
            }
           
            Console.WriteLine();
           
            Console.WriteLine("enter a name: ");
            string n= Console.ReadLine();
            if(bbb.Contains(n+" "))
                Console.WriteLine("found");
            else
                Console.WriteLine("not found");
            Console.ReadLine();
        }
    }

No comments: