| | |
Counting occurences in C
![]() |
•
•
Join Date: Oct 2005
Posts: 6
Reputation:
Solved Threads: 0
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.
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.
Here is one way to do it. There are probably several other ways too.
C Syntax (Toggle Plain Text)
std::string n = "1233321"; char s = '3'; int count = 0; for(int i = 0; i < n.length(); i++) if(n[i] == s) count++;
![]() |
Similar Threads
- Loop counting odd and even numbers (C++)
- counting lesson(for the slow among us) (Posting Games)
- Need Help counting Array Length (C++)
- Counting post count (Social Media and Online Communities)
Other Threads in the C Forum
- Previous Thread: returning by reference
- Next Thread: passing command line arguments
Views: 1479 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for C
#include .net api array arrays binary binarysearch c++ char character code codeblocks coke command conversion convert curl database decimal dev-c++ directory dude dynamic engrish error exec execv factorial fflush fgets file floatingpointvalidation fork function functions givemetehcodez grade graphics homework i/o include input insert int integer intmain() keyboard lazy line linked linkedlist linux list lists loop malloc matrix memory mysql no-effort output overwrite path pipe pointer pointers prime problem process program programming read recursion recursive recv reverse scanf segmentationfault select server socketprograming special spoonfeeding string strings strtok structures student subscript system testing tftp turbo-c unbuffered unix user variable va_list windows windows-mobile






