Thread: Need your help guys with C language!

  1. #1
    Registered User
    Join Date
    Jan 2015
    Posts
    4

    Exclamation Need your help guys with C language!

    Hello everyone, I am Beka, recently i got from my university email that i should do some little task in C language (Microsoft Visual Studio). I hope you guys can help me , help is really appreciated. I am sure who knows C language this task is only 5-10 min work. Its really easy and you are my chance. i will attach the picture of my task.


    Thank you all, i hope you will consider my request and dedicate me 10 min to help. I really need this.
    Thanks again!
    All the best!

    Here is the task:

    Need your help guys with C language!-untitled-png

  2. #2
    Registered User
    Join Date
    Dec 2014
    Posts
    11
    Sorry, but without even trying, nobody will help you here, read the homework policies and so on
    just start to code the beginning and if you have questions, then you will receive help here

  3. #3
    Registered User
    Join Date
    Jan 2015
    Posts
    4
    Here is the code i was trying to create first and second requirement , but its not working :|
    Code:
    #include <stdlib.h>#include <time.h>
    
    
    int main()
    {
    	int N = 10;
    	xtable = double[N];
    	ytable = double[N];
    	srand(time(NULL));
    	for (int i = 0; i < N; i++)
    	{
    		xtable[i] = rand();
    		ytable[i] = rand();
    		printf("(%lf, %lf)\n", xtable[i], ytable[i]);
    	}
    }

  4. #4
    Registered User
    Join Date
    Dec 2014
    Posts
    11
    well, there are some syntax errors, you must declare what you want to safe in xtable, this way the compiler doesn't know what type would be

    in c you declare an array like:
    Code:
    char buffer[100];
    the rest seems to be pretty ok, on the first look, try to declare your array right then the init should work and als omake sure that that printf does the right thing, cause i think without looking it up now, that there could be problems with long double placeholder, i just recommend to try it with just %f, but no garantuee
    Last edited by fendor; 01-18-2015 at 07:05 AM. Reason: really bad grammar

  5. #5
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    Quote Originally Posted by fendor View Post
    well, there are some syntax errors, you must declare what you want to safe in xtable, this way the compiler doesn't know what type would be

    in c you declare an array like:
    Code:
    char buffer[100];
    the rest seems to be pretty ok, on the first look, try to declare your array right then the init should work and als omake sure that that printf does the right thing, cause i think without looking it up now, that there could be problems with long double placeholder, i just recommend to try it with just %f, but no garantuee
    And your suggestion to be char array is incorrect.

    @B3CK - In C99 standard you need to declare everything (variables function etc) before you use them in the future code. Therefore, if you were to use an array to store your random number, you shouldhave it declared at the top. But you have is the name of the array and compiler dosent know of its type. You need to give it a type. rand() is a function which return an integer and you store them in array xtable and ytable. Therefore what should those array type be .... ?

    C is typed language and educate youself in type theory well before you indugle into the realm of C programming. Also read this FAQ on how to generate a valid random numbers and how to clamp the values.

    It is valid to omit "return 0" in your main function as per C99 as its implicit and the compiler by defaults return 0. However I would quite explicit in it and do place the "return 0;" at the end of your main function. To indicate successful termination of main.
    Last edited by ssharish2005; 01-18-2015 at 07:42 AM.
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

  6. #6
    Registered User
    Join Date
    Dec 2014
    Posts
    11
    @ssharish2005 I'm aware that this is not what he wants, and i never claimed it, I just said how you declare an array

  7. #7
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    @ B3CK – There appears to be more issues than I expected. Just a few to things to pick

    Code:
    #include <stdlib.h>
    #include <stdio.h>
    #include <time.h>
    Printf function is defined within the header stdio.h and there must be included before it can used. Or the compiler wont know its definition.

    Code:
        int xtable[N];
        int ytable[N];
    Thats how you declare your array in C.
    Code:
    <datatype> {arrayname}[size];
    Code:
     for( i = 0; i < N; i++)
    You cant decalre your variables just before the use. This is not C++. You need to declare the 'I' at the top before it can used.

    Code:
    printf("(%d, %d)\n", xtable[i], ytable[i]);
    Since your printing an integer, your format specifier should be “%d” and not “%lf”.
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by ssharish2005
    You cant decalre your variables just before the use. This is not C++. You need to declare the 'I' at the top before it can used.
    Actually, mixed declarations and code have been permitted since C99.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User
    Join Date
    Dec 2014
    Posts
    11
    ok, point to you, i tried my best, but you are right
    Last edited by fendor; 01-18-2015 at 08:18 AM.

  10. #10
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    Quote Originally Posted by laserlight View Post
    Actually, mixed declarations and code have been permitted since C99.
    Perhaps its time for me to refresh my c standards
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

  11. #11
    Registered User
    Join Date
    Jan 2015
    Posts
    4
    sorry guys i was absent because of my exams, i have a code of it, asked the teacher and it is i guess a convex hull. by generating numbers (black dots) i should calculate the lengh of a red line
    Need your help guys with C language!-untitledaa-png

  12. #12
    Registered User
    Join Date
    Sep 2014
    Posts
    364
    Hmm, two days without answer.
    Okay, i assume you have a list of random points (this is really simple).
    Now, what would you do to find the border if you have points on paper?
    You would looking around and find a point that is on the most outer area.
    How can you do that in a program?

    Hint: every point has an X- and Y-koordinate.
    Other have classes, we are class

  13. #13
    Ticked and off
    Join Date
    Oct 2011
    Location
    La-la land
    Posts
    1,728
    Don't bother, WoodSTokk. B3CK is just looking for someone else to do their homework.

    Even a cursory search on "convex hull" will lead to the Wikipedia Convex hull article. There, the Computation of convex hulls section refers to Convex hull algorithms as the main article. That one lists and links to several convex hull algorithms, the simplest of which is probably the Gift wrapping algorithm. That Wikipedia article has pseudocode you can implement. You only need to know about the perp dot product.

    As an exercise, I consider this a very good one, and relatively easy, too.

    I like the fact that in this particular exercise, using a structure to represent a point (a 2D vector) makes the logic simpler, and the code easier to follow: a pure win-win scenario.

    If the students are not familiar with basic 2D vector calculus, then all the lecturer needs to explain is that
    ĉ = (cX, cY)
    i.e. that a two-dimensional vector is just a pair of numbers, and that we use the notation because it makes things easier in the long run; in particular, we know stuff like
    â· = aXzY - aYzX = |â| || sin θ
    where θ is the signed angle between the two vectors. Now, that angle -- or rather, whether that angle is positive or negative -- tells us which direction is compared to â. Jumping a bit ahead, it leads to the realization that the sign of
    (ĉ - â)·( - â) = (cx - ax) (zy - ay) - (cy - ay) (zx - ax)
    tells whether point ĉ is to the left or to the right of line passing through points â and . It is zero if ĉ is exactly on the line. This would be much easier to see with a few figures explaining things, though.

    B3CK not being interested in this exercise enough to even try anything for themselves, is a very clear indication to me that they're a lost cause. Another vampire leech in the making, in other words.

  14. #14
    Registered User
    Join Date
    Jan 2015
    Posts
    4
    Thank you guys for your effort to help me, i used convex hull and grahams algorithm to determine to points and after i got the length between the points so sum of it was the length of the envelope. And about my absence : I already mentioned that i have exams now , so logically it means i dont have time , because of it i was so late for replies , thanks everybody

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Is C++ or C language is a high Level language?
    By uthmankhale in forum C++ Programming
    Replies: 5
    Last Post: 08-25-2011, 06:00 PM
  2. What do you guys think about this?
    By RobR in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 06-07-2006, 11:17 AM
  3. What's the Difference Between a Programming Language and a Scripting Language?
    By Krak in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 07-15-2005, 04:46 PM
  4. C Language And A Scripting Language
    By DarkSpy in forum C Programming
    Replies: 9
    Last Post: 06-26-2003, 08:05 AM
  5. Computer Language VS Spoken Language
    By Isometric in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 02-04-2002, 03:47 PM