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 are the basics of c#?
Why do we need events in c#?
How can you reference current thread of the method ?
Is stringbuilder better than string?
Explain About namespaces
Why we use get and set method in c#?
What is entity framework in c#?
What is xpath in c#?
How do you read an Excel sheet in C#?
What is iformatprovider in c#?
Explain the features of an abstract class in net.
What is Delegate and what is it used for ?
Can you use all access modifiers for all types?
What is the use of jit ? Jit (just - in - time) is a compiler which converts msil code to
What is code verification?