473,382 Members | 1,809 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

counting program

Hi, Im just a kid and I program in C++, and I started this week and know about basic input ouput, control structures, blah blah blah.

I wanted to make a program that keeps counting forever, and pulls out prime numbers, sending them to a specified .txt file.

Could anyone help me?
Aug 13 '07 #1
13 2099
sicarie
4,677 Expert Mod 4TB
Sure, I would start by deciding on how the program will identify a prime number. If you can write that into a function, you can call it every time you hit a number you want. After that, the rest of the program is just an infinite loop that increments a count, and then calls that check.
Aug 13 '07 #2
thanks sicarie.
could you give me an idea of the prime number method?
I use visual studio express C++ 2005
Aug 13 '07 #3
sicarie
4,677 Expert Mod 4TB
thanks sicarie.
could you give me an idea of the prime number method?
I use visual studio express C++ 2005
I would imagine that you could brute force it by using the modulus ( % ) operator, and checking all the numbers 2-9. And, obviously, you don't need to do it on any even number outside of two.
Aug 13 '07 #4
It makes sense! I'll try and figure it out from there.
If anyone else has any other suggestions or any code to help, please post it.
Thanks sicarie.
one more thing, what function could i use to make a code that finds the power of numbers, so you can let the user enter number and indices like:

NUMBER:
9
INDICES:
2
EXPRESSION FORMED: 9^2
OUTPUT: 81

I know how 2 do all of that apart from the formula 2 get the output.
Aug 13 '07 #5
JosAH
11,448 Expert 8TB
It makes sense! I'll try and figure it out from there.
If anyone else has any other suggestions or any code to help, please post it.
Thanks sicarie.
one more thing, what function could i use to make a code that finds the power of numbers, so you can let the user enter number and indices like:

NUMBER:
9
INDICES:
2
EXPRESSION FORMED: 9^2
OUTPUT: 81

I know how 2 do all of that apart from the formula 2 get the output.
That's not 'indices'; that's an exponent. Have a look at the pow() function in the
math library.

kind regards,

Jos
Aug 13 '07 #6
sicarie
4,677 Expert Mod 4TB
It makes sense! I'll try and figure it out from there.
If anyone else has any other suggestions or any code to help, please post it.
Thanks sicarie.
one more thing, what function could i use to make a code that finds the power of numbers, so you can let the user enter number and indices like:

NUMBER:
9
INDICES:
2
EXPRESSION FORMED: 9^2
OUTPUT: 81

I know how 2 do all of that apart from the formula 2 get the output.
Looks like you just need to read two variables in, and then use the function in the math.h library.

Check out cplusplus.com's tutorials section. They're pretty good.
Aug 13 '07 #7
thanks guys.
i found the pow function!
Aug 13 '07 #8
RRick
463 Expert 256MB
You can cut down on the exhaustive search by only using prime numbers that you've found. You will need to keep a list of them for this to work, but you have them anyway.

You don't have the check the whole range of the number, just check up to the integer ceiling of square root of the number being checked (whew!).

For example, to check that 23 is prime, just check all the prime numbers <= 5. Check (i.e. modulo == 0) for 2, 3, and 5. Stop when you find the first factor. In this case, 23 is prime.
Aug 14 '07 #9
Could anyone write me up a code?
Aug 14 '07 #10
sicarie
4,677 Expert Mod 4TB
Could anyone write me up a code?
Nope.

http://www.thescripts.com/forum/faq....ing_guidelines
Aug 14 '07 #11
oh, i see
never mind
Aug 14 '07 #12
sicarie
4,677 Expert Mod 4TB
oh, i see
never mind
We're here to help you, not do your work for you. That means if you get stuck, you can post your code and errors, and we'll help figure it out, but we won't write it for you.
Aug 14 '07 #13
We're here to help you, not do your work for you. That means if you get stuck, you can post your code and errors, and we'll help figure it out, but we won't write it for you.
Alright, I understand that. I saw the link.

Thanks for your help anyway
Aug 14 '07 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Kalle Rutanen | last post by:
Hello I implemented reference counting in my program, and found out many problems associated with it. I wonder if the following problems can be solved automatically rather manually ? 1. ...
1
by: Tony Johansson | last post by:
Hello Experts! I reading a book called programming with design pattern revealed by Tomasz Muldner and here I read something that I don't understand completely. It says "A garbarage...
8
by: DrNoose | last post by:
Hi! I'm writing a program that is supposed to read a line of input, count the words and the number of occurrences of each letter. Then it should prints the number of occurrences of each letter...
34
by: Mo Geffer | last post by:
Greetings: I have a question about the output of the sample program in section 1.5.3 Line Counting of K&R, Second Edition. Here's the program: /****************************************/...
5
by: Matt | last post by:
Alright, so I'm a little confused here...what exactly does this do? I've run it and it doesn't display anything, so I've typed some things into it, to see if it'd do something then, but to no...
16
by: pauldepstein | last post by:
How do I count the number of times I tested a program? My first attempt was this: #include <iostream> using namespace std; int main() {
4
by: aaronfude | last post by:
Hi, Please consider the following class (it's not really my class, but it's a good example for my question): class Vector { int myN; double *myX; Vector(int n) : myN(n), myX(new double) { }...
4
by: bigbagy | last post by:
Notes The programs will be compiled and tested on the machine which runs the Linux operating system. V3.4 of the GNU C/C++ compiler (gcc ,g++) must be used. A significant amount coding is...
27
by: Simon Biber | last post by:
I was reading http://en.wikipedia.org/wiki/Poker_probability which has a good description of how to count the frequency of different types of poker hands using a mathematical approach. A sample...
3
by: nitric | last post by:
hey guys, i'm really stuck on this program. It's basically a survey and I have to ask people what drinks they like. 1-4, coffee tea oj and lemonade. i'm having trouble counting the TOTAL NUMBER...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.