cs120 lab 1 - fall 2018

9
CS120 Lab 1 - Fall 2018 This should be an easy lab. You'll log in to the lab machines (use the user name and password sent to you by the CS department), write a little bit of code using some simple editors, and then compile and run things. When you are not in lab, you can still log in to the department machines, using ssh (on a Mac or Linux box), or putty (on a Windows box). Connect to remote.cs.binghamton.edu, and your files should be there. You can also use the University machines, with your PODS password, and connecting to bingsuns.binghamton.edu

Upload: others

Post on 14-Jan-2022

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS120 Lab 1 - Fall 2018

CS120 Lab 1 - Fall 2018

This should be an easy lab. You'll log in to the lab machines (use the user name and password sent to you by the CS department), write a little bit of code using some simple editors, and then compile and run things.

When you are not in lab, you can still log in to the department machines, using ssh (on a Mac or Linux box), or putty (on a Windows box). Connect to remote.cs.binghamton.edu, and your files should be there.

You can also use the University machines, with your PODS password, and connecting to bingsuns.binghamton.edu

Page 2: CS120 Lab 1 - Fall 2018

After you log in....Start up a terminal (you should be able to find it on the menu bar).

Page 3: CS120 Lab 1 - Fall 2018

Create a folder for your codemkdir is the command to create a folder. cd will change directories.

Page 4: CS120 Lab 1 - Fall 2018

Edit hello.cgedit is the easiest to use editor. Let's start with that.

Page 5: CS120 Lab 1 - Fall 2018

Write the code...When you're done, hit save, and then exit the editor

Page 6: CS120 Lab 1 - Fall 2018

Compile and Run

Page 7: CS120 Lab 1 - Fall 2018

Other Editors

gedit is fairly easy to use, but.... it works only if you're connected to the computer, and have a GUI desktop and a mouse. If you're working on a computer that's located somewhere in the Amazon Cloud, chances are you won't be able to use gedit, and will have to use something else.

emacs is worth knowing. It works great on a remote terminal connection. vi is worth knowing too. It also works on remote terminals. There are lots and lots and lots of text editors. Spend some time experimenting with them, to find ones you like.

If you use ssh or putty to connect to a remote machine, emacs or vi are your best bets for editors.

Page 8: CS120 Lab 1 - Fall 2018

Multiplication TableHere's code to print a simple multiplication table. TYPE THE CODE YOURSELF! It's good exercise for your fingers, and it will help lock in the C syntax. Get it running, and see if it makes sense.

#include <stdio.h>

int main(){ int i, j;

for (i = 0; i < 6; i = i + 1) { for (j = 0; j < 6; j = j + 1) { printf(" %3d", i * j); } printf("\n"); }}

Page 9: CS120 Lab 1 - Fall 2018

Simple Coding Challenge

Now... From scratch, make a program that calculates the sum of all the integers, from 1 to 100. You'll just need a simple "for" loop, a variable to calculate the running total, and you'll use printf to print out the result.

Yes, there's a closed form for this... The goal is to have a very simple coding job, where you bang something out from scratch. Get it running, show the TA, and that's all you've got to do for the day!