f i give input like 1,1,4,5,6,1,2,5,4,1,2, then output
should be like : 1-4, 2-2, 4-2, 5-1, 6-1 which means 1
occurs 4 times, 2 occurs 2 times like so.

Answer Posted / ganthi ganesh

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GanthiGanesh
{
class Program
{
static void Main(string[] args)
{
int one = 0, two = 0, thr = 0, fou = 0, fiv = 0,
six = 0, sev = 0, eig = 0, nin = 0, zer = 0;
Console.WriteLine("\nEnter here : ");
string ip = Console.ReadLine();
for (int i = 0; i < ip.Length - 1; )
{
char c1 = Convert.ToChar(ip[i]);
i++;
char c2 = Convert.ToChar(ip[i]);
if ((c1 == '0' || c1 == '1' || c1 == '2' ||
c1 == '3' || c1 == '4' || c1 == '5' || c1 == '6' || c1 ==
'7' || c1 == '8' || c1 == '9') && (c2 == ','))
{
i++;

}
else
{
Console.WriteLine("\nFormat error...
Press enter to exit...");
goto a;
}
}
for (int i = 0; i < ip.Length; i++)
{
char c = Convert.ToChar(ip[i]);
if (c == '1')
one++;
else if (c == '2')
two++;
else if (c == '3')
thr++;
else if (c == '4')
fou++;
else if (c == '5')
fiv++;
else if (c == '6')
six++;
else if (c == '7')
sev++;
else if (c == '8')
eig++;
else if (c == 9)
nin++;
else
zer++;
i++;
}
Console.WriteLine("\n");
if (one != 0)
Console.WriteLine("1-" + one.ToString());
if (two != 0)
Console.WriteLine("2-" + two.ToString());
if (thr != 0)
Console.WriteLine("3-" + thr.ToString());
if (fou != 0)
Console.WriteLine("4-" + fou.ToString());
if (fiv != 0)
Console.WriteLine("5-" + fiv.ToString());
if (six != 0)
Console.WriteLine("6-" + six.ToString());
if (sev != 0)
Console.WriteLine("7-" + sev.ToString());
if (eig != 0)
Console.WriteLine("8-" + eig.ToString());
if (nin != 0)
Console.WriteLine("9-" + nin.ToString());
if (zer != 0)
Console.WriteLine("0-" + zer.ToString());

a:
Console.Read();
}
}
}

Is This Answer Correct ?    1 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What Is A Satellite Assembly?

539


Why singleton pattern is used in c#?

532


Differentiate between response.expires and response.expiresabsolute?

541


What is type class in c#?

493


What is append in c#?

478






what is generics? can u explain 5 to 6 examples on generics that covers class,method,structure,list,delegates?

1442


Why do we Need of static class in c#?

642


What is constructor overloading in c#?

495


What is Inheritance in C#?

571


What are get and set in c#?

576


How assembly versioning in .NET prevent DLL Hell problem?

510


Can we override static class in c#?

477


How does the lifecycle of Windows services differ from Standard EXE?

516


How to implement singleton design pattern in c#?

467


Which one is trusted and which one is untrusted?

509