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
What Is A Satellite Assembly?
Why singleton pattern is used in c#?
Differentiate between response.expires and response.expiresabsolute?
What is type class in c#?
What is append in c#?
what is generics? can u explain 5 to 6 examples on generics that covers class,method,structure,list,delegates?
Why do we Need of static class in c#?
What is constructor overloading in c#?
What is Inheritance in C#?
What are get and set in c#?
How assembly versioning in .NET prevent DLL Hell problem?
Can we override static class in c#?
How does the lifecycle of Windows services differ from Standard EXE?
How to implement singleton design pattern in c#?
Which one is trusted and which one is untrusted?