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 / shadab
using System;
class abc
{
public static void Main()
{
Console.WriteLine("Enter your number with
comma Like this 1,1,4,5,6,1,2,5,4,1,2 ");
string str=Console.ReadLine();
char []a=str.ToCharArray();
int
ctr1=0,ctr2=0,ctr3=0,ctr4=0,ctr5=0,ctr6=0,ctr7=0,ctr8=0,ctr9
=0,ctr0=0;
for(int i=0;i<a.Length;i=i+2)
{
if(Convert.ToInt32(a[i].ToString())
==1)
{
ctr1++;
}
if(Convert.ToInt32(a[i].ToString())
==2)
{
ctr2++;
}
if(Convert.ToInt32(a[i].ToString())
==3)
{
ctr3++;
}
if(Convert.ToInt32(a[i].ToString())
==4)
{
ctr4++;
}
if(Convert.ToInt32(a[i].ToString())
==5)
{
ctr5++;
}
if(Convert.ToInt32(a[i].ToString())
==6)
{
ctr6++;
}
if(Convert.ToInt32(a[i].ToString())
==7)
{
ctr7++;
}
if(Convert.ToInt32(a[i].ToString())
==8)
{
ctr8++;
}
if(Convert.ToInt32(a[i].ToString())
==9)
{
ctr9++;
}
if(Convert.ToInt32(a[i].ToString())
==0)
{
ctr0++;
}
}
Console.WriteLine("1 Occurs "+ctr1);
Console.WriteLine("2 Occurs "+ctr2);
Console.WriteLine("3 Occurs "+ctr3);
Console.WriteLine("4 Occurs "+ctr4);
Console.WriteLine("5 Occurs "+ctr5);
Console.WriteLine("6 Occurs "+ctr6);
Console.WriteLine("7 Occurs "+ctr7);
Console.WriteLine("8 Occurs "+ctr8);
Console.WriteLine("9 Occurs "+ctr9);
Console.WriteLine("0 Occurs "+ctr0);
}
}
| Is This Answer Correct ? | 3 Yes | 0 No |
Post New Answer View All Answers
What is the difference between interface and inheritance in c#?
Is null empty or whitespace c#?
What is difference between C# and VB.NET?
Illustrate the differences between the system.array.copyto() and system.array.clone()?
What is ado c#?
How many digits are in an integer?
what is a constructor? What is a destructor?
Why is aws serverless?
What are satellite assemblies?
Is c# scripting language?
Why do we use inheritance in c#?
What is a float?
Explain the difference between abstract class and interface.
Define Final Class in C#
What is uint16?