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?
13 2099
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.
thanks sicarie.
could you give me an idea of the prime number method?
I use visual studio express C++ 2005
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.
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.
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
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.
thanks guys.
i found the pow function!
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.
Could anyone write me up a code?
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.
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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. ...
|
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...
|
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...
|
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:
/****************************************/...
|
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...
|
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()
{
|
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) { }...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |