C++ prime number logic [closed] - c++

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm creating a program that will output whether a number is prime or not. although, I'm trying to make it a little more complicated. I created a vector which I now want to store every prime number up to and including the number input by the user.
And then for the number input by the user (i.e. if the user types 13) will return true for the function hence it is a prime number. Here are some examples:
**U
primechecker() : plist(2) {;}
bool operator()(int);
3 5 7
then 3 5 6 7 7

The reason your vector is starting with two zeros is because you are initializing it with two elements of the default constructor:
primechecker() : plist(2)
Check out the documentation of std::vector (you are using the 'fill constructor')

Related

Who can explain this code ? Why it shows 1 [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
How does this work?
int a=5<=5;
cout<<a; // output : 1
Who can explain why output is 1?
That's because
<= has higher priority than = so it is calculated first.
5 <= 5 returns a boolean, which is true.
It is converted into an integer, which is 1.
then 1 is assigned to a.
so a equals 1 now.
5<=5 is true which, when converted to an integer is 1.
You assign this value to a which then holds the value 1. Which you then output.
You may want to read https://en.cppreference.com/w/cpp/language/operator_precedence

Identification possibility of sorting an array by deleting not more than one element [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Program gets a number of int arrays with size [2; 2000]. The question is: can that arrays get sorted after deleting not more than one element.
Examples:
2 16 3 3 - after deleting '16' it would be non-increasing array.
4 16 3 15 - there is no way to make it sorted.
Simple way: deliting first incorrect element and checking the fact of sorting. It takes too much time if there is a great number of arrays or that arrays are big-sizes.
Except cases, there incorrect element is first or last, and there array size is less than 4, in what way cheking that possibility can be accelerated
simply iterate through the array, and if you notice N_x > N_x+1 remove N_x, and mark that you removed 1 number...
in case you found another N_y > N_y+1 where y!=x, then it can't be sorted.
I'll leave the implementation for you, as it is your homework after-all.

Write a Regular Expression which identifies numbers divisible by 11 [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
For a study I am doing everyone gets assigned a unique number.
All unique numbers are divisble by 11 (this is done because it makes sequential numbers quite different from each other).
I would ideally like a regex which I can use to check that the number entered in the study_id field is an acceptable value - e.g divisible by 11.
I will have leading zeroes to a maximum of 5 digits
So:
00011 - Acceptable
00012 - Not Acceptable
13211 - Acceptable
13221 - Not Acceptable
Any suggestions gratefully received
This isn't possible because there are no textual similarities between numbers that are divisible by 11. Regex is used for text matching.
For example 000165 is divisible by 11 as is 00011.
The best way to validate the number is to divide it by 11 and see if there is any remainder. So in Excel you'd do this:
=IF(MOD(165, 11) = 0, "VALID", "INVALID")
Or C# you'd do something like this
bool isValid = 165 % 11 == 0;
(Disclaimer I'm not familiar with ODK so I can't provide a suitable sample; I've just guessed on the best language to write in)

How to find the MAX in any given list of numbers? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Is it possible to find the highest number in a list given any arbitrary number of items in the list? If so, please let me know how it can be done. I'm fairly new to Scheme.
You can use max function. Since your input is list of numbers, you can use apply function.
> (max 1 2 3 4)
4
> (apply max '(1 2 3 4 5 6 100 89 23))
100
>

Why C++ not have in starting double main() or like that and only int/void main()? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Also how would I write a program to work on a very large number. I want to find the largest prime factor of a number in the range of 600000000000
Because that int main () returns an exit code of the program. If returned 0 - everything is fine. You need to perform calculations in this function because it is the program entry point. If the number is too large advise to use the example of long arithmetic.
int main => return 0; which indicates if the program finished it's running as the programmer expected. Return 2^31 gives one enough numbers for indicating error codes.
For large numbers linked lists can be used.