Thread: Series of C problems

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

    Series of C problems

    Hello! I am a first year student in Cybernetics. I went to this college because I wanted to learn a lot of IT, Programming and all that. We do courses and labs in English (I don't live in an English-speaking country). The problem is that our C Programming teacher has little to no knowledge in English, yet she still tries to speak it and refuses to use out mother-tongue to actually teach us something. So we basically don't understand anything that she's saying and the textbooks jump straight into difficult stuff and we don't have the knowledge to do them.
    Anyway, I have an exam coming up on Friday and she gave us a list of programs that we need to know in order to be able to pass the exam. I have managed to find a solution for the first one (arithmetic mean) and learn and understand it but I am having a difficult time finding a solution for the others. If any one of you has the time or has a few examples for either of them that you would like to share, I would really appreciate it. Here is the list she gave us:

    List of programs for the final examination:
    -Arithmetical and geometrical means
    -intersection and reunion of two vectors
    -Interclasarea
    -Value of a polynomial in a point
    -find a value and all positions of that value in a vector
    -find a value using binary search
    -min and max in all positions
    -product of two matrices
    -product of a matrtix with a vector and a product of a vector with a matrix
    -main diagonal and secondary diagonal above and below
    -the sum of all triangles
    -find the vectorial product of every two lines/columns
    -find the vectorial of two by two
    -calculate using a subprogram the number of positive numbers of each columns in a matrix
    -find a line in which all the elements are positive/negative

    I did the first one (arithmetic mean) like this and it worked, but I also need the others. I promise you this is not homework or work, I just need them for study purposes.

    Code:
    #include <stdio.h>
    #include <conio.h>
    
    void main()
    {
        int n, i;
        float a[100], AM, sum = 0;
        printf("Please enter the number of terms \n");
        scanf("%d", &n);
        printf("Please assign a value to the %d terms \n", n);
        for (i = 1; i <= n; i++)
        {
            scanf("%f", &a[i]);
            sum += a[i];
        }
        AM = sum / n;
        printf("The arithmetic mean is = %f", AM);
        getch();
    
    
    }


    Thank you!

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,412
    Have you tried doing the others?
    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

  3. #3
    Registered User
    Join Date
    Jan 2015
    Posts
    33
    I tried searching for a solution for many of them but I haven't managed to find any. All I was able to find was the Arithmetic-Geometric Mean but that looks and is too complicated for me to understand and I also don't need it for my exam.

  4. #4
    Registered User
    Join Date
    Jan 2015
    Posts
    33
    My only hope is studying some examples like I did with the Arithmetic Mean.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,412
    Quote Originally Posted by OctavianC
    I tried searching for a solution for many of them but I haven't managed to find any.
    Instead of searching for solutions, come up with your own solutions. After all, you might be faced with a problem that you have not seen before, in which case what will help you is the problem solving skill and knowledge of programming that you gained while working out your own solutions, since you would not have any solution at hand to just write out from memory.

    For many of your problems what you need is to understand the algorithm. From there you can implement it.
    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

  6. #6

  7. #7
    Registered User
    Join Date
    Jan 2015
    Posts
    33
    One of my colleagues told me that it should be "int main()" instead of "void main()". Codeblocks returned an error when using void, but Visual Studio did not, so I kept it that way. I changed it now, thanks .

  8. #8
    Registered User
    Join Date
    Jan 2015
    Posts
    33
    How can one be able to come up with solutions to problems by using means which he does not understand? :P I appreciate your advice and I sure hope to be able to do so one day soon, but one week to learn all of that from scratch with no help at all from nobody is not possible.

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,412
    Quote Originally Posted by OctavianC
    How can one be able to come up with solutions to problems by using means which he does not understand?
    Consider the first one: Arithmetical and geometrical means. You can start by searching the Web for "arithmetical mean". You will probably find search results related to "arithmetic mean". Some of these will tell you what is the meaning of the term and provide a mathematical description of the concept. From there, you can think about how to implement the algorithm, formula, etc.
    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

  10. #10
    Registered User
    Join Date
    Jan 2015
    Posts
    33
    Quote Originally Posted by laserlight View Post
    Consider the first one: Arithmetical and geometrical means. You can start by searching the Web for "arithmetical mean". You will probably find search results related to "arithmetic mean". Some of these will tell you what is the meaning of the term and provide a mathematical description of the concept. From there, you can think about how to implement the algorithm, formula, etc.
    That's how I solved the first one, but after that things get complex . I don't think you understand that I have almost no knowledge of Programming whatsoever. You're telling me I should grab a sword for the first time in my life and go head on against a samurai and everything will be fine. That's not really helping me. Thanks anyway.

  11. #11
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    528
    Quote Originally Posted by laserlight View Post
    Consider the first one: Arithmetical and geometrical means. You can start by searching the Web for "arithmetical mean". You will probably find search results related to "arithmetic mean". Some of these will tell you what is the meaning of the term and provide a mathematical description of the concept. From there, you can think about how to implement the algorithm, formula, etc.
    The problems feel more like mathematical problems than programming problems, which is odd and shows lack of competence in the lecturer.

  12. #12
    Registered User
    Join Date
    Jan 2015
    Posts
    33
    Quote Originally Posted by Aslaville View Post
    The problems feel more like mathematical problems than programming problems, which is odd and shows lack of competence in the lecturer.
    As I said in the first post, she is not a good teacher at all, that's why I am asking this community for help.

  13. #13
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,412
    Quote Originally Posted by OctavianC
    I don't think you understand that I have almost no knowledge of Programming whatsoever.
    Hmm... have you considered working through an introductory book on C programming?

    Quote Originally Posted by OctavianC
    You're telling me I should grab a sword for the first time in my life and go head on against a samurai and everything will be fine.
    Since you want to use such an analogy, I note that one important aspect of training in martial arts involves sparring with other students or the teacher. Practice weapons might be used to avoid (serious) injury. Likewise, you won't die from attempting these practice problems.

    Quote Originally Posted by OctavianC
    That's not really helping me.
    I would be happy to help you work out solutions to the various problems that you have listed, but I will only do so after I have seen you make an attempt.
    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

  14. #14
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    528
    Quote Originally Posted by OctavianC View Post
    As I said in the first post, she is not a good teacher at all, that's why I am asking this community for help.
    With this problems the only thing I could tell you to do is (Friday is a week off )

    Take one problem at a time, search it on the web, get the formula, all that without even thinking about any programming.

    After you have understood how to manually do something, try to implement it in C.

    Come back with the particular formulae for a give question, start a new thread(or even this thread) show us the code you have tried to write and am sure you will get some help.

    Also with unless you have left out some of the details I find most of your question ambiguous. They could actually be interpreted in very many ways.

    For instance:

    -product of two matrices
    Does this mean a two by two matrix or a three by three matrix or what? If you talk of a matrix you need to know more about a matrix more specifically how many items does it have.

    -the sum of all triangles
    What exactly do you mean here?

    Well, I am hoping you left out the details since you were too lazy to type

  15. #15
    Registered User
    Join Date
    Jan 2015
    Posts
    33
    Quote Originally Posted by laserlight View Post
    Hmm... have you considered working through an introductory book on C programming?


    Since you want to use such an analogy, I note that one important aspect of training in martial arts involves sparring with other students or the teacher. Practice weapons might be used to avoid (serious) injury. Likewise, you won't die from attempting these practice problems.


    I would be happy to help you work out solutions to the various problems that you have listed, but I will only do so after I have seen you make an attempt.
    I found the solution for the Geometrical Mean, but it took me 3 hours. All I was doing wrong was not including math.h (since I didn't know that I should do that).

    To answer your question, I have considered working through an introductory book. I studied C for Dummies for a while but it didn't really help that much since it barely got through the basics in 500 pages or so. I have also tried other study books but they went too fast and started from a too high level for me to understand anything. Also, with one week left until my exam, I don't think I have the necessary time to do so. All I'm trying to do is pass with all the knowledge I can gather until then. I'm a fast learner, but I need a teacher, someone who can answer my questions, provide me with examples and so on. But all I can ask now is 'How, from start to finish, do I make the union of two vectors in the C Programming Language?'. Do you understand my problem?

    This is the Geometrical Mean of two numbers:

    Code:
    #include <stdio.h>
    #include <math.h>
    int main()
    {
        float a, b, GM;
        printf("Insert the two numbers for the geometrical mean\n");
        scanf("%f", &a);
        scanf("%f", &b);
        GM = sqrt(a*b);
        printf(" The geometrical mean of %f and %f is %f\n", a, b, GM);
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What is this series?
    By shansajid in forum C Programming
    Replies: 4
    Last Post: 01-15-2013, 05:26 AM
  2. Help me with this series
    By NoUse in forum C Programming
    Replies: 6
    Last Post: 01-22-2009, 11:57 PM

Tags for this Thread