Adblock breaks this site

Learning C, can anyone help me out?

Discussion in 'Programming General' started by BoredDanMan, Mar 6, 2013.

  1. BoredDanMan

    BoredDanMan Newcomer

    Joined:
    Mar 6, 2013
    Posts:
    1
    Referrals:
    0
    Sythe Gold:
    0
    Learning C, can anyone help me out?

    First I'd like to say that I had an old account on Sythe long ago when I was into runescape and botting and all that jazz, but now that I've gotten older and am not really playing runescape anymore, I remembered that Sythe also had a section on the forums for programming. I'm getting into programming, and I figured the first language I should learn is probably C. I'm now trying to make a code that will do the following things, but I don't really know where to start.

    1). Accept some form of user input whether it's from a file or typed in for 10 ordered pairs (x and y variables, both float). At the moment i just have two arrays, one for x and one for y.

    2). Use simple linear regression to calculate the best fit line for the given points

    3). print the best fit line and r value

    Note I have never actually taken statistics so I'm using my calc knowledge and wikipedia to understand how Linear Regression works. Finding the r value seems annoying and I dont really get it.



    Update: I've figured it out except for a small problem. When doing the linear regression with certain data sets there is a divide by 0 error and I cant seem to fix it
     
  2. Blupig

    Blupig BEEF TOILET
    $5 USD Donor

    Joined:
    Nov 23, 2006
    Posts:
    7,145
    Referrals:
    16
    Sythe Gold:
    1,609
    Discord Unique ID:
    178533992981594112
    Valentine's Singing Competition Winner Member of the Month Winner MushyMuncher Gohan has AIDS Extreme Homosex World War 3 I'm LAAAAAAAME
    Off Topic Participant
    Learning C, can anyone help me out?

    It's not really related to your question, but you probably shouldn't be doing C for your first language
     
  3. Sythe

    Sythe Join our discord

    test

    Administrator Village Drunk

    Joined:
    Apr 21, 2005
    Posts:
    8,071
    Referrals:
    465
    Sythe Gold:
    5,271
    Discord Unique ID:
    742989175824842802
    Discord Username:
    Sythe
    Dolan Duck Dolan Trump Supporting Business ???
    Poképedia
    Clefairy Jigglypuff
    Who did this to my freakin' car!
    Hell yeah boooi
    Tier 3 Prizebox Toast Wallet User
    I'm LAAAAAAAME Rust Player Mewtwo Mew Live Free or Die Poké Prizebox (42) Dat Boi
    Learning C, can anyone help me out?

    There are about a thousand ways you can do this. Here is a simple one:

    Code:
    #include <stdio.h>
    
    int main(int argc, char** argv) {
    
    	float x[10], y[10];
    
    	for (int i = 0; i < 10; i++) {
    
    		if (scanf("%f %f\n", &(x[i]), &(y[i])) != 2) {
    			printf("Could not parse line. Expecting 0.001 0.002 for example\n");
    			break;
    		}
    
    	}
    
    	for (int i = 0; i < 10; i++) printf("%d: %f, %f\n", i, x[i], y[i]);
    
    }
    Sounds like your homework. Won't be writing that code for you. But linear regression is pretty straight forward I think you can figure it out.

    If you are writing plain ansi C you wont be able to print a graph. You will need a library.

    Use a debugger such a gdb to find the bug. Then add something like if (x == 0) break;

    C is an excellent first language because it will teach you all the core and most important concepts in programming. It is just difficult to learn.
     
  4. Govind

    Govind The One Musketeer
    Mudkips Highly Respected Retired Administrator

    Joined:
    Apr 22, 2005
    Posts:
    7,825
    Referrals:
    13
    Sythe Gold:
    23
    Prove it! Trole Tier 1 Prizebox Tortoise Penis Le Monkey UWotM8? Wait, do you not have an Archer rank? Potamus
    Learning C, can anyone help me out?

    Other than objects.
     
  5. Sythe

    Sythe Join our discord

    test

    Administrator Village Drunk

    Joined:
    Apr 21, 2005
    Posts:
    8,071
    Referrals:
    465
    Sythe Gold:
    5,271
    Discord Unique ID:
    742989175824842802
    Discord Username:
    Sythe
    Dolan Duck Dolan Trump Supporting Business ???
    Poképedia
    Clefairy Jigglypuff
    Who did this to my freakin' car!
    Hell yeah boooi
    Tier 3 Prizebox Toast Wallet User
    I'm LAAAAAAAME Rust Player Mewtwo Mew Live Free or Die Poké Prizebox (42) Dat Boi
    Learning C, can anyone help me out?

    Not true. C has structs.

    Every essential programming concept is in C. Remember that OO gets compiled down to procedural assembly at the end of the day -- It's just a way of organizing your code for maximum reuse and maintainability.

    In terms of programming a computer (as in a physical CPU) C gives you everything you need both concept-wise and in practical terms.

    Of course I am slightly biased, I've tutored C for almost half a decade.
     
  6. SuF

    SuF Legend
    Pirate Retired Global Moderator

    Joined:
    Jan 21, 2007
    Posts:
    14,212
    Referrals:
    28
    Sythe Gold:
    1,234
    Discord Unique ID:
    203283096668340224
    <3 n4n0 Two Factor Authentication User Community Participant Spam Forum Participant Sythe's 10th Anniversary
    Learning C, can anyone help me out?

    Structs only give you half the picture. OOP is the most predominant paradigm in programming today and I think it's a lot easier to go from an OOP background and then learn C then go from C to OOP but I'm most likely bias because I started with and have kept with Java. I will say that functional programming is most certainly not something you should learn first. Recursion is damn hard to wrap your mind around when you first start it.
     
  7. Blupig

    Blupig BEEF TOILET
    $5 USD Donor

    Joined:
    Nov 23, 2006
    Posts:
    7,145
    Referrals:
    16
    Sythe Gold:
    1,609
    Discord Unique ID:
    178533992981594112
    Valentine's Singing Competition Winner Member of the Month Winner MushyMuncher Gohan has AIDS Extreme Homosex World War 3 I'm LAAAAAAAME
    Off Topic Participant
    Learning C, can anyone help me out?

    Don't get me wrong it's a great language, but the reason I wouldn't recommend it as a first to learn is because it can get pretty discouraging. I took a couple C++ classes last year and it was a breeze for me since I've been programming for years, but for those who were starting out, they had a lot of trouble and were completely turned off from programming after the end of the first semester.

    I feel that programming is something that should be eased into, with a high-level common syntax language like C# or Java. With those you still learn your syntax, your logic, and gain the ability to think "in code". Afterwards, learning C would be infinitely easier and most likely would be more fun (not to mention at that point, after learning a high-level language, the user would notice the benefits of a lower-level language). Idk, just my 2 cents. I think it's a lot easier to go from high-level to low-level as opposed to the opposite.

    EDIT: Just realized that SuF and I are on the same ground here. I could also be bias, seeing as I started with VB6 -> VB.NET -> Java -> C# -> C++
     
< Facebook game hacks | Java Help >


 
 
Adblock breaks this site