954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Counting occurrence of numbers in C

Hi all.

I need help creating a prog. in C that can count the occurrence of numbers. The prog. should go like this:

Enter input 1 = 223335
Enter input 2 = 2

Output = The number 2 appears twice in "223335".

The first input can be any 6 numbers and the second input should only be 1 number.

Could someone help me out?

stabule
Newbie Poster
6 posts since Oct 2005
Reputation Points: 10
Solved Threads: 0
 

You can take a char array and store the number in it and then take another character variable to hold the number for which u want to find the occurence.
Then take a for loop and compare the entered character with each element of char array
.....and count the total occurence in that for loop

SpS
Posting Pro
599 posts since Aug 2005
Reputation Points: 70
Solved Threads: 32
 

I'm still a beginner, don't really know how to write the coding. Could you help me out?

stabule
Newbie Poster
6 posts since Oct 2005
Reputation Points: 10
Solved Threads: 0
 
I'm still a beginner, don't really know how to write the coding. Could you help me out?


In that case you need study your books first and then post in forums(if you are stuck somewhere)....see the rules....i could have posted the code for you but that would not help you much....show some effort.....

SpS
Posting Pro
599 posts since Aug 2005
Reputation Points: 70
Solved Threads: 32
 

I've been working on this for 2 weeks and have done my share of studying. The reason I'm posting here is because I really need help. I understand the logic and the sequence in which it must be written in, but I'm really stuck with the coding.

stabule
Newbie Poster
6 posts since Oct 2005
Reputation Points: 10
Solved Threads: 0
 

Which part of the logic and the sequence do you not know how to do?

Rashakil Fol
Super Senior Demiposter
Team Colleague
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177
 
I've been working on this for 2 weeks and have done my share of studying. The reason I'm posting here is because I really need help. I understand the logic and the sequence in which it must be written in, but I'm really stuck with the coding.



Basically, you're going to have to post your existing code to show that you've put in some effort.

winbatch
Posting Pro in Training
466 posts since Feb 2005
Reputation Points: 68
Solved Threads: 18
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You