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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Mar 13, 2015, 6:30 AM
Pankaj Kumar ChoudharyPosted Mar 13, 2015, 6:08 AM
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();
}
Manish Kumar ChoudharyPosted Mar 13, 2015, 5:49 AM
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();
}
}
}