• Log in or sign up for an account here: https://www.sythe.org/login

Learning C, can anyone help me out?

BoredDanMan

Newcomer
Joined
Mar 6, 2013
Sythe Gold
0
Messages
1
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
 
Valentine's Singing Competition Winner
Sythe Awards 2015 Winner
Sythe Awards 2016 Winner
Sythe Awards 2020 Winner
Member of the Month Winner
MushyMuncher
Gohan has AIDS
Extreme Homosex
World War 3
I'm LAAAAAAAME
Discord Verified
Off Topic Participant
It's not really related to your question, but you probably shouldn't be doing C for your first language
 
Supporting Business
Discord Voice
Poképedia
Who did this to my freakin' car!
Dat Boi
Dolan Duck
Dolan Trump
I'm LAAAAAAAME
Live Free or Die
Mew
Mewtwo
PHP Shit Show 2k26
Poké Prizebox
Rust Player
Sythe Awards 2016 Winner
Sythe Awards 2017 Winner
Sythe Awards 2019 Winner
SythePro Subscriber
Tier 3 Prizebox
Toast Wallet User
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.

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]);

}

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

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.

3). print the best fit line and r value

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

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

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

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

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.
 
Le Monkey
PHP Shit Show 2k26
Potamus
Prove it!
Sythe Awards 2011 Winner
Tier 1 Prizebox
Tortoise Penis
Trole
UWotM8?
Wait, do you not have an Archer rank?
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.
Other than objects.
 
Supporting Business
Discord Voice
Poképedia
Who did this to my freakin' car!
Dat Boi
Dolan Duck
Dolan Trump
I'm LAAAAAAAME
Live Free or Die
Mew
Mewtwo
PHP Shit Show 2k26
Poké Prizebox
Rust Player
Sythe Awards 2016 Winner
Sythe Awards 2017 Winner
Sythe Awards 2019 Winner
SythePro Subscriber
Tier 3 Prizebox
Toast Wallet User
Other than objects.

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.
 
<3 n4n0
Discord Verified
Two Factor Authentication User
Community Participant
Spam Forum Participant
Sythe's 10th Anniversary
Sythe Awards 2011 Winner
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.

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.
 
Valentine's Singing Competition Winner
Sythe Awards 2015 Winner
Sythe Awards 2016 Winner
Sythe Awards 2020 Winner
Member of the Month Winner
MushyMuncher
Gohan has AIDS
Extreme Homosex
World War 3
I'm LAAAAAAAME
Discord Verified
Off Topic Participant
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.

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++
 
duelarena.gg
Back
Top