Monday, 29 April 2013

john needs to create a program that defines a charcter array with five elements. he also needs to accept a character the user, and count the number of times charactet in the character array.


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace ConsoleApplication4



{

 class duplicate



{

 static void Main(string[] args)



{

 char[] ch = new char[5] { 'a', 'b', 'a', 'c', 'd' };

 int i, count = 0;

 Console.WriteLine("enter a character:");

 char input = Convert.ToChar(Console.ReadLine());

 for (i = 0; i < 5; i++)
{

 if (ch[i] == input)
{

count++;

}

}

 Console.WriteLine("{0} appears {1} times in the character array", input, count);

 Console.ReadLine();

}

}

}

No comments:

Post a Comment