Q1>write a program in c# which returns the each character and how many times repeated like follows:
If "INDIA" is string -it will return like I is 2 times,N,D,A is One time
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Manish Kumar ChoudharyRank #339 · 7.4K reputationPosted Mar 13, 2015, 1:49 AM EDT
Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SchoolDays
{
class Program
{
static void Main(string[] args)
{
string input = "WWW.C-SHARPCORNER.COM";
while (input.Length > 0)
{
Console.Write(input[0] + " : ");
int count = 0;
for (int j = 0; j < input.Length; j++)
{
if (input[0] == input[j])
{
count++;
}
}
Console.WriteLine(count);
input = input.Replace(input[0].ToString(),string.Empty);
}
Console.ReadLine();
}
}
}
Pankaj Kumar ChoudharyRank #80 · 24.4K reputationPosted Mar 13, 2015, 2:08 AM EDT
static unsafe void Main(string[] args)
{
string str;
Console.WriteLine("Enter your string ");
str = Console.ReadLine();
char[] Char_ar;
Char_ar = str.ToCharArray();
int count, status ;
for (int i = 0; i < Char_ar.Length; i++)
{
count = 0;
status = 0;
for (int j = 0; j < i; j++)
{
if (Char_ar[i] == Char_ar[j])
{
status = 1;
break;
}
}
if (status == 0)
{
for (int j = i; j < Char_ar.Length; j++)
{
if (Char_ar[i] == Char_ar[j])
count++;
}
Console.WriteLine("{0} {1} Times ", Char_ar[i], count);
}
}
Console.ReadKey();
}
VulpesRank #55 · 29.2K reputationPosted Mar 13, 2015, 2:30 AM EDT