find occurance of a number
take input from users like 123234567 and then find how many times a number appear the number to find must be taken from user input ,,, show your code I want to check memory optimization for Hook up solutions
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.
Pankaj Kumar ChoudharyPosted Jul 6, 2015, 10:48 PM
int n;
int[] Number = new int[10] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
Console.WriteLine("Enter Number");
str = Console.ReadLine();
foreach (char c in str)
{
n = int.Parse(c.ToString());
Number[n] += 1;
}
for (int i = 0; i < 10; i++)
Console.WriteLine("{0} = {1}", i, Number[i]);
Console.ReadKey();
Rahul PrajapatPosted Jul 6, 2015, 10:02 PM
int n;
int[] Number=new int[10]{0,0,0,0,0,0,0,0,0,0};
Console.WriteLine("Enter Number");
str=Console.ReadLine();
foreach (char c in str)
{
n=int.Parse(c.ToString());
switch (n)
{
case 0:
Number[n]++;
break;
case 1:
Number[n]++;
break;
case 2:
Number[n]++;
break;
case 3:
Number[n]++;
break;
case 4:
Number[n]++;
break;
case 5:
Number[n]++;
break;
case 6:
Number[n]++;
break;
case 7:
Number[n]++;
break;
case 8:
Number[n]++;
break;
case 9:
Number[n]++;
break;
}
}
for (int i = 0; i < 10; i++)
Console.WriteLine("{0} = {1}", i, Number[i]);
Console.ReadKey();
Hariharasudhan ChandramurthyPosted Jul 6, 2015, 4:48 PM