so if there is 4 people in the room for example
person 1 = 0
person 2 = 1
person 3 = 2
person 4 = 3
??
i knew i should paid attention during algebra
Anyone "have" this book they recommend for beginners?
Absolute Beginner's Guide to C, Second Edition
Greg Perry
Ok so i just finished Lecture 1 of Lesson 0 , all is simple enough brehs , but can someone explain this in another format? Its a simple algorithm to explain how to count people in a room
Now i know this is basic algebra but every time i tried to follow the county i was wrong , i kept being off by 1 or 2
@Kodie
also for those wondering Lesson 0 is two 1 hour lectures + assignments
so if there is 4 people in the room for example
person 1 = 0
person 2 = 1
person 3 = 2
person 4 = 3
??
i knew i should paid attention during algebra
Perfect explanation. This will help when people start to deal with performing functions on arraysLet N = 0
N is 0 before any counting actually starts. It's just a variable that starts out with a value of 0.
for each person in room
This basically tells the program how many times you want to do 'something'. In this case it's using the number of individual people in the room. So if you have 4 people, you're going to do 'something' 4 times.
N = N + 1
This is the 'something' that you're going to do. Again, in this case, if there are 4 people/persons in the room, we're going to do 'N = N + 1' four times.
So
For Person 1: Do N = N + 1
Again, when we created N, we gave it a value of 0. So this is going to be
0 = 0 + 1
Before we move on, it's important to note that in programming, the "=" sign doesn't mean "equals". It's an "assignment" operator, which basically means whatever is on the left gets set to the value of whatever is on the right.
So the '0' on the left is going to get set to the value of the '0 + 1' on the right (so as you can see, it's not exactly like algebra). Another way to say it is 0 "gets" 0 + 1 for short, or it might be easier to verbalize it as 0 "becomes" 0 + 1, or 0 "is" 0 + 1 (I say "is" or "gets"). It might look a little weird here, since we're substituting the real numbers in for N, but it'll make more sense when you think of assigning values to variables.
0 = 0 + 1 (0 "gets set to the value of" 0 + 1)
0 = 1 (simplified the calculation on the right side; now it means 0 gets set to 1)
1
N = N + 1 (N "gets set to the value of" N + 1)
N = 1 (N gets set to 1)
N is 1
So this was the first time we completed the N = N + 1 algorithm. If we're using the same example as before, where we said there are 4 people, we're going to be doing N = N + 1 three more times.
For Person 2: Do N = N + 1
Here N starts out as 1, which was the result from the first time we did this algorithm. So:
1 = 1 + 1 (1 gets set to the value of 1 + 1)
1 = 2 (1 gets set to 2)
2
N = N + 1 (N gets set to the value of N + 1)
N = 2 (N gets set to 2)
N is 2
For Person 3: Do N = N + 1
Here N starts out as 2, which was the result from the second time we did this algorithm. So:
2 = 2 + 1
2 = 3
3
N = 2 + 1
N = 3
N is 3
For Person 4: Do N = N + 1
Here N starts out as 3, which was the result from third time we did this algorithm. So:
3 = 3 + 1
3 = 4
4
N = 3 + 1
N = 4
N is 4
Now, let's simplify
Set up my variables:
N = 0
Do something with them:
For Person 1: Do N = N + 1
Result: N = 1
For Person 2: Do N = N + 1
Result: N = 2
For Person 3: Do N = N + 1
Result: N = 3
For Person 4: Do N = N + 1
Result: N = 4
At the end of this program, N = 4.
We've successfully counted the number of people in the room.
Hope that helps.
Great answer!Let N = 0
N is 0 before any counting actually starts. It's just a variable that starts out with a value of 0.
for each person in room
This basically tells the program how many times you want to do 'something'. In this case it's using the number of individual people in the room. So if you have 4 people, you're going to do 'something' 4 times.
N = N + 1
This is the 'something' that you're going to do. Again, in this case, if there are 4 people/persons in the room, we're going to do 'N = N + 1' four times.
So
For Person 1: Do N = N + 1
Again, when we created N, we gave it a value of 0. So this is going to be
0 = 0 + 1
Before we move on, it's important to note that in programming, the "=" sign doesn't mean "equals". It's an "assignment" operator, which basically means whatever is on the left gets set to the value of whatever is on the right.
So the '0' on the left is going to get set to the value of the '0 + 1' on the right (so as you can see, it's not exactly like algebra). Another way to say it is 0 "gets" 0 + 1 for short, or it might be easier to verbalize it as 0 "becomes" 0 + 1, or 0 "is" 0 + 1 (I say "is" or "gets"). It might look a little weird here, since we're substituting the real numbers in for N, but it'll make more sense when you think of assigning values to variables.
0 = 0 + 1 (0 "gets set to the value of" 0 + 1)
0 = 1 (simplified the calculation on the right side; now it means 0 gets set to 1)
1
N = N + 1 (N "gets set to the value of" N + 1)
N = 1 (N gets set to 1)
N is 1
So this was the first time we completed the N = N + 1 algorithm. If we're using the same example as before, where we said there are 4 people, we're going to be doing N = N + 1 three more times.
For Person 2: Do N = N + 1
Here N starts out as 1, which was the result from the first time we did this algorithm. So:
1 = 1 + 1 (1 gets set to the value of 1 + 1)
1 = 2 (1 gets set to 2)
2
N = N + 1 (N gets set to the value of N + 1)
N = 2 (N gets set to 2)
N is 2
For Person 3: Do N = N + 1
Here N starts out as 2, which was the result from the second time we did this algorithm. So:
2 = 2 + 1
2 = 3
3
N = 2 + 1
N = 3
N is 3
For Person 4: Do N = N + 1
Here N starts out as 3, which was the result from third time we did this algorithm. So:
3 = 3 + 1
3 = 4
4
N = 3 + 1
N = 4
N is 4
Now, let's simplify
Set up my variables:
N = 0
Do something with them:
For Person 1: Do N = N + 1
Result: N = 1
For Person 2: Do N = N + 1
Result: N = 2
For Person 3: Do N = N + 1
Result: N = 3
For Person 4: Do N = N + 1
Result: N = 4
At the end of this program, N = 4.
We've successfully counted the number of people in the room.
Hope that helps.
PDF, EPUB or Mobi?Anyone "have" this book they recommend for beginners?
Absolute Beginner's Guide to C, Second Edition
Greg Perry
http://avaxhome.cc/ebooks/programming_development/c/0672305100__beC.htmlAnyone "have" this book they recommend for beginners?
Absolute Beginner's Guide to C, Second Edition
Greg Perry
EditPDF, EPUB or Mobi?
Any of you using your coli name for nick names?
6 cert 6 figure coli gangI signed up.
I'm a web developer and looking to further my PHP and SQL back-end programming. Any one hit me up if you're into the web and wanna start smashing this course out with the coli brehs.
In fact any one wanna make a Coli group, including discussions about the week lectures? Let's get these certs brehs