Hi all.
I need some help counting specific numbers in C. The programme should accept two sets of numbers. It should then count how many of the second number is in the first set.

For example:
First input = 23387
Second input = 3
Ouput = "Number 3 appears twice in 23387."

Can someone help me out with the coding ? I'd really appreciate any help.

The easiest way is to input both as strings, not integers, then simply iterator through the string. Attempting to use integers makes that a lot more difficult.

Mind giving me a headstart ?

Here is one way to do it. There are probably several other ways too.

std::string n = "1233321";
char s = '3';
int count = 0;
for(int i = 0; i < n.length(); i++)
  if(n[i] == s)

Thanx bro. I'll try it out. Cheers.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.