1. DLP Flash Christmas Competition + Writing Marathon 2024!

    Competition topic: Magical New Year!

    Marathon goal? Crank out words!

    Check the marathon thread or competition thread for details.

    Dismiss Notice
  2. Hi there, Guest

    Only registered users can really experience what DLP has to offer. Many forums are only accessible if you have an account. Why don't you register?
    Dismiss Notice
  3. Introducing for your Perusing Pleasure

    New Thread Thursday
    +
    Shit Post Sunday

    READ ME
    Dismiss Notice

Programming !! :D

Discussion in 'Tech Support' started by Skykes, Dec 7, 2010.

  1. Trooper

    Trooper Death Eater

    Joined:
    Jan 8, 2009
    Messages:
    970
    Location:
    Bangalore, India
    What you're using skykes, is the most straight forward, Brute force approach.
    You need to think on easing the pressure a little bit. ;)

    Here's some direction :

    Check out Matrix indices, as in the form of an A[j]. Isn't that wut they're called? >_>

    Also, as far as branching and looping are concerned, I prefer for-loops in this particular problem.

    Edit : Lol Ninja'd.

    And even ignoring all the memory problems, etc...You're actually missing the Math portion of the thing. I mean, its not just knowing how to multiply matrices.

    Once you figure out how to use indices with Matrices...I.e Matrix in the form of a double array A[j], try to just write a program that inputs values in the places with loops.

    You'll get the trick/notice how the whole [j] thing works for a matrix and its pretty much smooth sailing from there.

    And one more thing...If is not a loop...Its a conditional branch. As in it decides whether to go one way or another.
     
    Last edited: Dec 7, 2010
  2. Johnny Farrar

    Johnny Farrar High Inquisitor

    Joined:
    Mar 14, 2009
    Messages:
    521
    Location:
    In front of a Computer.
    printf is okay other then you didn't use a closing paren for the first one.

    For scanf, to store the values from the stdin you need to specify the memory address which is done with an ampersand (&), that is, every single variable in your scanf function should have an ampersand

    Also, the the number of format specifiers should correspond to the number of memory addresses. You've put only one.

    Also, if is not a loop, it's decision statement that allows the program to decide whether or not to print a statement depending on the Boolean of its condition.

    Loops are those that iterate, like while and for.
     
  3. Skykes

    Skykes Minister of Magic DLP Supporter

    Joined:
    May 14, 2006
    Messages:
    1,353
    Location:
    Ireland
    Oh right, thanks for clearing that up. I'm looking at the for statement in my book now(A guide to C programming by Paul Kelly). But it's pretty confusing.

    I'm going to take a break from this, and go for a swim. Back in 2 hours.
     
  4. Johnny Farrar

    Johnny Farrar High Inquisitor

    Joined:
    Mar 14, 2009
    Messages:
    521
    Location:
    In front of a Computer.
    Never heard of that book. But if you don't already have it then get The C Programming Language, Second Edition by Ritchie and Kernighan. It's The Book for C language.
     
  5. silverlasso

    silverlasso Minister of Magic DLP Supporter

    Joined:
    Dec 7, 2007
    Messages:
    1,302
    Location:
    San Francisco
    Here are a list of things you should probably understand before you can successfully do your assignment:

    -if/else statements
    -loops (for and while)
    -printf and scanf operation and syntax
    -arrays (this includes multidimensional arrays)
    -declaring separate functions/preprocessor directives

    You won't need to use pointers, though (as in, actually declaring int *ptr or something).

    Anyways, you have about a week to do this, so you should be able to learn enough to finish the assignment in that time. The concepts that you have to grasp aren't too tough; you just need to invest some time.
     
  6. Nukular Winter

    Nukular Winter The Chosen One DLP Supporter

    Joined:
    Jun 8, 2006
    Messages:
    2,216
    Location:
    Seattle
    Honest advice: if you haven't learned how to use an array at this point you are WAY behind. Two months is a lot of class to miss, if you're ever planning to learn this for real you should really, really consider dropping the class if you can and retaking it when you're able to attend the lectures and learn the material. Even if you manage to get this program to work, you're absolutely hosed for the exams.



    If that's not an option, have you considered taking input from a file? You can pass a filename to your program at startup and skip the printf()/scanf() loop (unless the assignment specifically requires that you interact with the user, you should skip it. It's not worth the aggravation...)

    If you don't know how to do that (and I suspect you might not), Google is your friend. It's pretty straightforward, and would allow you to focus on the matrix math/manipulating arrays part of the assignment.
     
  7. Skykes

    Skykes Minister of Magic DLP Supporter

    Joined:
    May 14, 2006
    Messages:
    1,353
    Location:
    Ireland
    So I don't think I can do it that way NW.
     
  8. Nukular Winter

    Nukular Winter The Chosen One DLP Supporter

    Joined:
    Jun 8, 2006
    Messages:
    2,216
    Location:
    Seattle
    That's not what that requirement says at all...
     
  9. KrzaQ

    KrzaQ Denarii Host DLP Supporter

    Joined:
    May 9, 2008
    Messages:
    1,404
    Location:
    Poland
    You should've informed us that it had to be C/C++ :/ Now I've wasted half of my day writing this awesome solution for you.

    On a side note, if you can choose between C and C++, C++ is a better choice.
     
  10. Sesc

    Sesc Slytherin at Heart Moderator

    Joined:
    Dec 20, 2007
    Messages:
    6,216
    Gender:
    Male
    Location:
    Blocksberg, Germany
    Hahaha, KrzaQ :mrgreen:

    OP, use that. Seriously.
     
  11. Kthr

    Kthr Unspeakable DLP Supporter

    Joined:
    Sep 1, 2008
    Messages:
    713
    Location:
    São Paulo, Brazil
    This thread reminds me I gotta study for my own test on programming, which I have to take in two days.

    The worst part is that my teacher took a look at my last exam (We had a week to write 5 programs in C), asked all kind of questions about every single program, and gave me a 6/10(I needed 7.5 to pass without doing one more exam).

    Then comes in one of the girls from my class(who has boobs) hands over a shiton of googled stuff, and gets a 8 without aswering a single question.

    (tumbs up for university teachers.)

    /rant.

    So, back in topic, as people said, use the usual int A[j] matrix stuff, and don't forget about the rules for mutiplying them (as in A[j], B[k][l]: you must force the user to input a j equal to k)

    Then it's a matter of using a couple "for" commands to read/write each line and column

    Since I did this last night:
    Code:
    float A[m][n],B[p][q];
        for (i=0;i<m;i++)
        {
            for (j=0;j<n;j++)
            {
                printf("\n Type A(%i,%i): ",i+1,j+1);
                scanf("%f",&A[i][j]);
            }
        }
        for (i=0;i<p;i++)
        {
            for (j=0;j<q;j++)
            {
                printf("\n Type B(%i,%i): ",i+1,j+1);
                scanf("%f",&B[i][j]);
    
    Understanding what this is is crucial to start doing the math with it, so don't just copy&paste.
     
    Last edited: Dec 7, 2010
  12. silverlasso

    silverlasso Minister of Magic DLP Supporter

    Joined:
    Dec 7, 2007
    Messages:
    1,302
    Location:
    San Francisco
  13. Skykes

    Skykes Minister of Magic DLP Supporter

    Joined:
    May 14, 2006
    Messages:
    1,353
    Location:
    Ireland
  14. Nukular Winter

    Nukular Winter The Chosen One DLP Supporter

    Joined:
    Jun 8, 2006
    Messages:
    2,216
    Location:
    Seattle
    Did you attend any of those lectures?
     
  15. Skykes

    Skykes Minister of Magic DLP Supporter

    Joined:
    May 14, 2006
    Messages:
    1,353
    Location:
    Ireland
    About 40% of them.
     
  16. Seratin

    Seratin Proudmander –§ Prestigious §– DLP Supporter

    Joined:
    Oct 14, 2007
    Messages:
    293
    Location:
    Dún na ngall
    High Score:
    5,792
    And what percentage of those did you pay attention in?
     
  17. Speakers

    Speakers Backtraced

    Joined:
    Feb 7, 2010
    Messages:
    697
    Honestly, read the notes. Ask us better questions than thoughts on notes. Have you gone through them all? What specific thing is troubling you and why? People have given you plenty of tutorial sources, have you read any of them?
     
  18. Skykes

    Skykes Minister of Magic DLP Supporter

    Joined:
    May 14, 2006
    Messages:
    1,353
    Location:
    Ireland
    When I attended I sat at the very front and paid 100% attention.

    I have other projects due with more urgent deadlines. I was planning on getting this done on the weekend.


    Also: Does anybody know what the 3 pin *(Kettle lead)* cable for psu's is called?
     
  19. silverlasso

    silverlasso Minister of Magic DLP Supporter

    Joined:
    Dec 7, 2007
    Messages:
    1,302
    Location:
    San Francisco
    I think the notes you linked are both succinct and very useful. There are several code samples that are easily adaptable to your assignment.

    Seems like a pretty slow class, though.
     
  20. Kthr

    Kthr Unspeakable DLP Supporter

    Joined:
    Sep 1, 2008
    Messages:
    713
    Location:
    São Paulo, Brazil
    While on the subject, anyone mind explaining to me why I can't use a fuction to exchange the value of two variables between them, unless I use pointers? Such as:

    Code:
    float exchange (float a, float b)
    {
        float aux;
        aux=a;
        a=b;
        b=aux;
    }
    .
    .
    .
    
    exchange (x[i], x[j])
    
    instead of:

    Code:
    float exchange (float *a, float *b)
    {
        float aux;
        aux=*a;
        *a=*b;
        b=aux;
    }
    .
    .
    .
    
    exchange (&x[i], &x[j])
    If it matters, the rest of the program creates one vector(x[n]) allowing the user to insert "n" numbers so the computer sort then in a crescent manner. The exchange function come after a couple "for"s and an "if" to compare each pair of terms in the vector and printing them in a file.

    I'm afraid the only friend I have online right now taking the course with me can't help :(
     
    Last edited: Dec 8, 2010
Loading...