|
[C] Competition Problems
|
|
06-20-2010, 01:11 PM
Post: #1
|
|||
|
|||
|
[C] Competition Problems
Distance Between Points
Code: /*Factors Code: /*Fahrenheit-Celsius Code: /*"Character is determined more by the lack of certain experiences than by those one has had." Friedrich Nietzsche |
|||
|
06-20-2010, 02:42 PM
Post: #2
|
|||
|
|||
|
RE: [C] Competition Problems
Here is a challenge. Should be simple but good exercise. Have a user enter 20 positive integers in a array. Then only print out the integers that are not a duplicate.
|
|||
|
06-20-2010, 02:46 PM
Post: #3
|
|||
|
|||
|
RE: [C] Competition Problems
Heh, ill try/
"Character is determined more by the lack of certain experiences than by those one has had." Friedrich Nietzsche |
|||
|
06-20-2010, 02:57 PM
Post: #4
|
|||
|
|||
| RE: [C] Competition Problems | |||
|
06-20-2010, 03:06 PM
Post: #5
|
|||
|
|||
|
RE: [C] Competition Problems
Damn...this is kind of a tough one. I've tried reversing the array and comparing it to itself/ But that would only work if it was the same in the opposite position. I think this could be easier achieved in python where you could add all the number to a list and check the array against that
"Character is determined more by the lack of certain experiences than by those one has had." Friedrich Nietzsche |
|||
|
06-20-2010, 06:49 PM
Post: #6
|
|||
|
|||
|
RE: [C] Competition Problems
Nice task for exercise
I am not really pro at C languages, but I can do it!
Read rules ![]()
|
|||
|
06-21-2010, 12:19 AM
Post: #7
|
|||
|
|||
| RE: [C] Competition Problems | |||
|
06-21-2010, 12:42 AM
(This post was last modified: 07-30-2010 08:26 PM by drdebcol.)
Post: #8
|
|||
|
|||
|
RE: [C] Competition Problems
Well basically, that first one is Euclidean distance between points in 2d.
You have it illustrated here : http://www.pro9ramming.com/length-of-pat...-t-88.html And i would like to change the code a bit. First you don't have to call power function, you can just make a macro statement and define sqr or sqare : Code: #define sqr(x) (x)*(x)![]() Also you printed it with conversion "%d" and that is float number. If you printf a float number (that is FP-Floating Point) with integer conversion, you can get something really different than the thing you wanted. So changed code should look like this : Code: #include <stdio.h>Well second task, is almost the same as this here : http://www.pro9ramming.com/decomposition...t-604.html The task i did in that thread is a decomposition of prime factors. And this task that Back_track did is a decomposition to all factors. It is very good solution Back_track. I changed it to look more like C lol : Code: #include <stdio.h>And about third task. Well because you printed float value on one decimal, you could use "float Farenheit" or "double Farenheit" except "int Farenheit". That would be all. Generally good job Back_track !!! Also this one that Codecaine suggested : Have a user enter 20 positive integers in a array. Then only print out the integers that are not a duplicate. Well i did it for n integers. And i used "unsigned" because you said "positive integers". Also i used dynamic memory allocation with function malloc(), so that user can enter length of array that he wants, without limits (of course memory is always the limit). Code: #include <stdio.h>There's a fine line between genius and insanity. I have erased this line. Oscar Levant There's a fine line between an administrator and black hat hacker. I have erased this line. Dr DEBCOL |
|||
|
06-22-2010, 05:43 AM
Post: #9
|
|||
|
|||
|
RE: [C] Competition Problems
Hmmm Drdebcol. I get the gist of the problem you solved but can you explain it a bit better?
"Character is determined more by the lack of certain experiences than by those one has had." Friedrich Nietzsche |
|||
|
06-22-2010, 06:23 AM
Post: #10
|
|||
|
|||
RE: [C] Competition Problems
(06-22-2010 05:43 AM)Back_track Wrote: Hmmm Drdebcol. I get the gist of the problem you solved but can you explain it a bit better?Well this is an easy task. You have 2 loops (i and j) going through all members of array. If members are different (that means that i is not equal to j or i!=j) and a[i]=a[j] that means that member is a duplicate. You just need to est k to zero (false) and later in (i) loop check if k=1 (true) and than print that number. And about malloc() function find on the internet. There's a fine line between genius and insanity. I have erased this line. Oscar Levant There's a fine line between an administrator and black hat hacker. I have erased this line. Dr DEBCOL |
|||
|
« Next Oldest | Next Newest »
|







I am not really pro at C languages, but I can do it!