Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 days ago.
Improve this question
This is what I have so far 1 When I call my function in int main, It prints infinite random numbers. I also have trouble with the array parameter and arguments. The question I am answering states "Create a program with a function that accepts three arguments: an integer array, an integer size that indicates how many elements are in the array, and an integer n . The function should display all of the numbers in the array that are greater than the number n."
I want the program to print out the numbers in the array that are greater than a number stated as an argument for the parameter N. Would really appreciate some help.
Related
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 5 years ago.
Improve this question
what is the difference between
int n,s;
cin>>n;
s=n*1/10;
cout<<s;
and
int n,s;
cin>>n;
s=n*10/100;
cout<<s;
?
and also 100/1000 and 1000/10000 and ...
when I enter big numbers for n(such as 1000000000),it has different outputs.
I got my answer!!
the problem is because of order of evaluation and also overflowing in integer
If you have a large number and multiply by 10, the number may overflow. This means that the number that you're trying to store is too big to fit into the memory allocated for that number. The exact consequence for a signed integer overflowing is called "undefined behaviour" meaning that it's up to the compiler to decide how to deal with this.
When you divide by 100, the number you're dividing is now different than the number than you're expecting - thus giving you the wrong result.
This is likely only a problem on debug builds; as the compiler will probably replace the *10/100 to be /10 as part of the optimisation that it will do for a release build.
The other item where you multiply by 1 and then divide by 10 will always be defined however, since the multiplication will leave the number unchanged.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Can someone explain what's happening in this line of code and how it's valid.
char output[][32] = {"Not present in trie", "Present in trie"};
It's declaring an array of n arrays of type char[32], where n is deduced from the number of initializers in the initializer list (in this case 2).
When the variable is initialized, the contents of the provided string literals are copied into the array (string literals can be used to initialize char arrays in C and C++).
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have a problem with this snippet of code:
for(int i=n;i>0;i--)
for(int j=0;j<i;j++)
if(docel[j]==docel[i])
docel.erase(j);
Why is that that my program doesn't compile? I also tried:
docel.erase(docel.at(j))
erase takes an iterator, not an index value. A simple fix is to use docel.erase(docel.begin() + j);
But your code looks buggy on two counts:
Take care not to increment j if you erase the (j)th element though: you'll skip over values.
You'll also need to adjust n if the number of elements in docel is reduced.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have this line of code:
out = std::min(x - 1, y - 1);
But it is returning the larger of the two quantities. How can this be?
This can only happen if x and y are unsigned types and one of them is zero.
Subtracting 1 from an unsigned value 0 will cause an unsigned value to wrap around to the largest possible value for that type. Hence the other value will be smaller.
As a side note: only blame your compiler / STL as a very last resort.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
I'm creating a program in C and I need to use relative prime numbers in sequence using an algorithm so that the user can select the first number in the sequence.
So far I have managed to create a function that creates relative prime numbers based on one or more inputted by a user but not one that finds the next smallest relative prime.
Either that or a way to produce the smallest relative prime number to a user defined number would be ideal.
Any ideas?
Also, I cannot get gcd to work so I created my own. Do i have to include a specific library other than math.h and stdio.h?
If you want to find the next smallest relative prime, then I think you need to loop from the user's inputted number (e.g. if users input 3, then you need to loop from 4), and then check whether that number is relatively prime.
To check whether two numbers are relatively prime, you can use gcd, and one very famous algorithm to do this is to use Euclid's algorithm. You don't need to include a specific library, it's basically just looping and doing modulo. Take a look at this link.