I would like to determine the odd numbers from a given sequence of numbers. After determining,I want to display those odd numbers.
Can you help me?
I can only use loops,if-elseif-else,swtich,break and continue. Anything beyond the said lessons are not allowed.
Thank you.
P.S
I am sorry if I cannot provide the code. I want to code it on my own.I just need some ideas from you.
Steps:
Loop through the array(sequence) element by element
If an array_element%2 is one, display the number.(% is the modulus operator and gets the remainder of the division of its operands)
Now just convert the above steps into code.
Related
So, I have tried to do the same in a case of array of structures where 'char name[100]' is the only data member.
1st part of the code
2nd part of the code
The problem that I have encountered here is that once I provide a no. of names during program runtime, the output screen either does not print anything afterwards, or, prints the data without sorting it.
output screen
I did not get any compile time errors so I believe that there is a flaw in the logic.
There's this another method I tried hoping to get positive results. I type-casted characters to integers hoping that ASCII values could be used to compare. But, the results are exactly the same (undesired results).
updated logic of the 2nd part of the code
I hope somebody helps me find a way to correct this logic or provide another logic that is efficient.
the sorting logic you used is good , but from what is see the use of function's in C need's to be provided by pointers. other wise all the data inside the function will born and die inside the function , and the all the variables in the Main will stay the same as given, that explains why the output is the same as the input
try to print inside the sorting function's to see if this is the problem.
For a maths project I am currently using the CAS Maxima (wxMaxima). As the project is almost finished I would like to remain with Maxima, but there is one problem left:
The issue is that I have to convert a certain polynomial P by making all its coefficients positive. I.e. adding up the absolutes of all coefficients (but not taking the absolute value of the whole polynomial), for example
P(...)=-15x^3+3y^2-4x^2
turns to
P'(...)=15x^3+3y^2+4x^2
I could not find an implemented function that would help me with this. And could not find a solution by implementing it with a map function. Do you know a way to solve this issue?
Thank you for your help!
Jonas
You can calculate a sum of absolute values:
P:-15*x^3+3*y^2-4*x^2;
P2:sum(abs(args(P)[i]),i,1,length(args(P)));
>> 3*y^2+15*x^2*abs(x)+4*x^2
(unfortunately, here is abs(x) but you can use subst(x,abs(x),P2))
The same with map:
P2:map(abs,P);
Or convert an expresstion to string and replace "-" to "+":
s:string(P);
s2:ssubst("+","-",s);
P2:eval_string(s2);
>> 3*y^2+15*x^3+4*x^2
So, I am a basic programmer in flash and this weekend I have to make a small mini game. This is where I get confused...I have 1 movieclip which has 5 labels ( each showing a different shape). I also have a dynamic text field which I have text or (a string) that will need to match the movieclip. Meaning, if the text displays circle, and the shape is circle, if you click the screen you win. if they dont match, you lose. So I am asking this in order to find out, how to create 2 arrays, randomize them then compare the value. I know how to set everything on timers and give scores, I just cant get figure this part out. AS3 and I are having a bad day. Any ideas, even pseudo code helps...or just a flow , something please ! lol thanks in advance
Regarding randomizing an array, have a look at this elaborate article at Activetuts, which specifically aims at Actionscript. It provides documented code with clear illustrations and tips. You could also check out the Fisher-Yates shuffle for some pseudo-code.
I don't quite get your question with regards to comparing the strings.. In AS3, you can use == to see if the strings are equal.
For this I think to properly solve it I need to show that sigma(logn) is its lower bound. I know all of the comparisons in my book run in O(nlogn), but im not sure how to form this into a concrete answer.
I think you've misread the problem: The array you are given is sorted. You are not sorting it. You are accessing it. Let's play a game. I pick a US state and you try to guess it. Every guess I will tell you if my chosen state is alphabetically before or after your guessed state. How many guesses do you need? The problem gives you a great clue with binary search.
Add this to your general algorithm toolbox: To show a lower bound is valid (but not necessarily tight), assume there exists an upper bound that is smaller, and do a proof by contradiction. For your problem, this should be doable.
In a simple way, i have an array of 10 values for example..and i would like to multiply each value with 5. Can i actually just do the following?
for (i = 0 ; i <10 ; i++)
{
x[i]=x[i]*5;
}
And what about getting square for values in the array and be stored back into the same array? As in I want x[i]=x[i]*x[i].
Can I actually just do the multiplication like that?
I tried a couple of combination but it didnt really work..hope someone can help out! Thanks!
This is perfectly fine.
edited now that the language has been specified
Yes, this "just works" in C.
Can you post more about the errors you're seeing so that we can try to help you out?