Write a program that reads a string from the user and generates a histogram for the characters encountered in this string. A histogram is a representation of how many times each character appears in the input string. Use function Histogram that takes the string as input and displays its histogram.
For example,
String: My name is Nermeen
Histogram //output
M *
y *
space ***
n **
a *
m **
e ****
i *
s *
N *
r *
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string Sentence = Console.ReadLine();
char[] letters = Sentence.ToCharArray();
for (int i = 0; i < letters.Length; i++)
{
int count = 0;
for (int j = 0; j < letters.Length; j++)
{
if (letters[i] == letters[j])
count++;
}
for (int k = 0; k <count ; k++)
Console.Write("{0} : *",letters[i]);
Console.WriteLine( );
}
}
}
}
The problem in my code is that some characters get repeated for example m:if there is another m in another place the program writes it again m:.would you please correct the code for me so that i could the program as the output required by problem.
thanks :)