Physics 306 Computing Lab 1: Hello, World!

Size: px
Start display at page:

Download "Physics 306 Computing Lab 1: Hello, World!"

Transcription

1 1. Introduction Physics 306 Computing Lab 1: Hello, World! In today s lab, you will learn how to write simple programs, to compile them, and to run them. You will learn about input and output, variables, and loops. If you have done computing before, the first couple weeks of the computer lab may be very simple for you. That s fine. In each of sections 3 through 7 below, you will work with variants of a single computer program. As you work each section, print out enough from the program (such as its original code and a copy of its output) to prove that you have done it, or talk to your instructor while in the lab so that he can mark down the fact that you did that part of the experiment. This week, work as far as you can in the writeup in two hours. If you get through it all in less than two hours, you can leave early. We will adjust the content of next week s lab depending on how far people get this week. Working computers can be both incredibly gratifying and incredibly frustrating. The main source of frustration is that a minor error (for example, a missing semi-colon) can cause a program to utterly fail to work, and the computer system will often not give you a clear explanation as to why it is failing. If you find yourself stuck on a point, get help talk to your friends in the class or to your instructor. 2. Setting up the computer We want to jump right in and start writing programs. But first, you need to have a place on the computer to store your work. Check your machine s desktop. If there is not a Physics306 folder, please make one. Make sure there are no spaces in the folder name (i.e., no space between Physics and 306. ) Within the Physics306 folder, make a folder for yourself (e.g., use the name part of your Bryn Mawr or Haverford address.) Again, make sure there are no spaces in the folder name. To make new folders in the MacOS finder, use shift- -N. 1

2 3. Hello, world! Start Microsoft Word. Create a new document. Select Tools AutoCorrect..., click on AutoCorrect, and de-select everything. This prevents Word from automatically capitalizing things as you type. Enter the following. It is important to get everything exactly right. #include <stdio.h> int main() { printf("hello, world!\n"); } Select File Save As..., and save the file using name hello.c and format Text Only with Line Breaks. When you specify the format (in the pull-down menu), Word might try to give the file name a.txt extension. Change it back to.c if necessary, so that the file name is hello.c. Save the file in the folder with your name. If Word is not displaying directories, click on the little arrow to the right of the file name in the Save as window, and a directory display will open up. After you click save, Word will give you a warning that formatting information will be lost. Click yes to continue saving the document. Next, start the Terminal program by clicking on the Terminal icon on the dock. It looks like this:. If you don t see this icon, you can run the Terminal program from the Finder. Type shift- -U to go to the Utilities folder, and click on Terminal there. (Note: if you are familiar with the X11 window system, feel free to use xterms with X11 instead of the MacOS Terminal program.) When the terminal pops up, it will display a message similar to this: mathphysics-dhcp174:~/ student$ This is called the prompt. The computer is waiting for you to type something. The prompt lists the computer name ( mathphysics-dhcp174 in this example). Although not yet obvious, the prompt also tells you which folder you are working in. Type cd Desktop/Physics306/myname, replacing myname with the name of the folder you created earlier. Whenever you type something like this, press return when you are done. You are now working within the folder you made on the desktop. We will usually use the word directory instead of folder, but they mean the same thing. Notice that the prompt has changed to reflect the new directory name. You can type pwd to see which directory you are working in. Type ls to list the files in the directory. There should be just a single file, hello.c, which you created a few minutes ago. 2

3 You are now ready to compile and run this program. Type gcc -o hello hello.c. If the computer prints error messages, then there is something wrong with your hello.c program. Double-check that it looks exactly like the listing above. If you can t find any problems, but you continue to get error messages, talk to your instructor. Type ls again. Now, in addition to hello.c, there is a second file, called hello. This file contains the actual computer instructions needed to execute the commands listed in hello.c. In other words, it is a computer program which you can run. Type./hello. (Notice the sequence: period, slash, hello.) The hello program will run and print out a message. If it does not do so, double check your program again. If you can t get it to work, ask for help. There are a number of lines in your short hello.c program which probably just look like gibberish, but it should be clear which part of the program is responsible for writing out the hello message. We ll talk about the rest of the gibberish on some other day. Modify the code to print out your name or the name of your pet fish or the name of your favorite math theorem. What s that \n thing in the program? Try leaving out the \n. What happens? What happens if you put an extra \n into the program, for example, hello\n, world!\n? Try it! There are other things you might try: \t, \b, \a. Instead of having the program s output be written to the terminal screen, you can have it saved in a file. Run./hello > a.txt. Nothing is displayed on the screen when you run this. Type ls and you will see that there is a new file, a.txt, in the directory. You could look at this file with a standard text editor like Word or TextEdit. Or, you can write it to the screen by typing cat a.txt. In fact, you can write any file to the screen. Try typing cat hello.c. To print any of these files, you can open them in Word or TextEdit and use the print ( -P) command. Or, in terminal, you can type, for example, lpr xyz.txt where xyz.txt is the name of the file. At the moment, it seems that the computers are set up to print to the printer in the computer lab, but sometimes they request the wrong paper tray. You may have to walk over to the printer and hit the checkmark button on the printer to get it to behave. 3

4 4. Arithmetic Time for another program. Use Word to enter the following. Give it a new name, such as multiply.c. If you would rather use a different editor (like MacOS s TextEdit, or the Unix editors vi or emacs), that s great. If you are going to do a lot of programming, you should learn to use vi or emacs. But please leave that for another day and get back to typing the following code into the computer. #include <stdio.h> int main() { int a, b, c; printf("type two numbers separated by a space:\n"); scanf("%d %d",&a,&b); c = a * b; } printf("the product of %d and %d is %d\n",a,b,c); Compile this and run it in the same way as you ran the hello program. When you type gcc -o multiply multiply.c, what you are doing is telling the computer to compile your program (i.e., to turn it into something the computer can run). The original file, that you wrote, is called the source code, and the runnable program produced by the compiler is called the executable or the binary file. The gcc command tells the compiler to put the executable into a new file called multiply. You can call the executable anything you wish; just change what is after the -o in the gcc command. You can also leave out the -o part entirely, and just write gcc multiply.c. What is the executable called in this case? Try it and see. By the way, the computer language you are using is called C. Our use of C is a somewhat arbitrary choice. Many computer languages would be capable of doing the work we want to do. What you learn using C you can easily apply to other languages. The C complier is, confusingly, called gcc. In MacOS (and many other systems), you can type cc instead of gcc, and the computer will run the same compiler. Different computers have different C compilers. The gcc compiler is very commonly used on MacOS, Linux, and other Unix-based computer systems. When you put.c at the end of a file name, that tells the compiler that it is a C program. Getting back to your program, once you ve convinced yourself that it works, change it to divide a by b instead of multiplying them together. Compile the program and try it out. What happens if you try to divide 10 by 3? Hmmm, looks like the program 4

5 only understands integers. Could that word int in the program have something to do with this? Try changing int a, b, c; to float a, b, c;, and change the characters %d to %f (in four separate places ). What happens? The process of defining a variable to be int or float or something else is called declaring the variable. Every variable you use must be declared before you use it. By now you will have noticed that every statement (that is, every command within a program) ends with a semi-colon. The only exception is the first line, which starts with a pound sign, #. The use of semi-colons to separate one statement from the next is a feature of many (but by no means all) computer languages. Ends of lines have no significance in C. You can put a single statement on multiple lines, for example: c = a * b; And you can put multiple commands on a single line: printf("type two numbers:\n"); scanf("%d %d",&a,&b); c=a*b; What s going on in the printf and scanf lines? Technically, these are both C functions. Among other things, this means that, in a program, they are always followed by something in parenthesis. In fact, it is common to call these functions printf() and scanf(). The parentheses are included in the names, even in casual conversation. (How do you pronounce punctuation marks? Look up Victor Borge phonetic punctuation on YouTube. But wait until after lab to do that.) So, what does printf() do? As you have gathered by now, printf() prints things out, that is, it writes them to the screen. Writing a bunch of letters to the screen is straightforward: printf("salut le Monde!\n"); The thing inside the quotation marks is called a format string. If you want to print an integer variable, put the characters %d in the format string, and list the variable name after the string: int a; a = 7; printf("my favorite number is %d.\n", a); If you want to print out more than one variable, put more than one %d in the format string: int a, b; a = 7; b = 3; printf("my favorite number is %d, but I also like %d.\n", a, b); You can print the same variable more than once: 5

6 int a; a = 7; printf("i love %d! %d is my favorite! %d! %d! %d!\n",a,a,a,a,a); To print a floating point number, use %f instead of %d : float a; a = 7.543; printf("personally, I prefer %f. I love decimals.\n",a); Printing both integers and floats is no problem: printf() function call: float a; int b; a = 7.543; b = 7; printf("the best is %f, but %d is also pretty good.\n",a,b); There are many, many other features of printf(). We ll talk about the some other time. The scanf() function is more-or-less the opposite of the printf() function. It takes one line of input from the keyboard and stores whatever is typed there into one or more variables: int a, b; float c; printf("type two integers separated by a space:\n"); scanf("%d %d",&a,&b); printf("now type in a floating point number:\n"); scanf("%f",&c); Note the peculiarity that you need to put & before the variable name in a scanf() function call. We ll talk about why that is at some later date. Are you tired of typing./ every time you run a command? In your terminal, type the following: echo $PATH. If you run a program like multiply without specifying which directory it is in, the computer will search all the directories listed in $PATH. The directory in which you are currently working is not on that list, so you have to specify it manually. That s what the./ is all about. The period means the current working directory. To add it to the path, do the following: PATH=.:$PATH. Now you can simply type multiply without the period and slash. You ll probably want to make this change to $PATH every time you start a terminal. 6

7 5. Going for a loop Now try this: #include <stdio.h> int main() { int i; float pi; float a; pi = ; } for (i=0; i<10; i++) { a = i*pi; printf ("%d times pi is approximately %f\n",i,a); } Compile and run this program. The program executes the same statements ten times, each time with a different value of i, starting at 0 and going as high as 9. This sort of thing is called a loop. In this program, i starts off at 0 (i=0), it is incremented by one each time the loop is run (i++), and it runs as long as i is less than 10 (i<10). The ten passes through the loop are called iterations of the loop, and i is called the loop index. The code that is run ten times is enclosed by brackets after the for command. 6. A variable-length loop Modify the above program so that it asks the user how many iterations he or she wants, and sets the upper limit of i to that value. You will need to add a new variable to the program to do this. If have trouble figuring out how to do this, ask someone for help. If you do something wrong and your program looks like it will run forever, type ctrl-c to stop it. 7. Factorial; how big can an integer be? You know that the a factorial, often written a!, is the product of the integers from 1 thorough a. So, for instance, 5! = =

8 Write a program which uses a loop to calculate the factorial of some number (we ll call it n). Do this by declaring a variable n, initially setting it to 1, and then multiplying it by the loop index in each iteration through the loop. Do everything with integers. Once you ve gotten that working, see how high a number you can calculate before problems start arising. There is a maximum value which integer numbers in this implementation of C are allowed to have. If you try to make a larger integer, strange things can happen. Explore! That s enough for today!.... Note: The idea of starting programming by writing a Hello, world program was popularized in the classic text The C Programming Language by Brian Kerninghan and Dennis Richie. It has become the de facto standard first program to write when learning any computer language. For more about this program, check out the Hello world program entry in Wikipedia. 8

ENCM 339 Fall 2017: Editing and Running Programs in the Lab

ENCM 339 Fall 2017: Editing and Running Programs in the Lab page 1 of 8 ENCM 339 Fall 2017: Editing and Running Programs in the Lab Steve Norman Department of Electrical & Computer Engineering University of Calgary September 2017 Introduction This document is a

More information

Physics 306 Computing Lab 5: A Little Bit of This, A Little Bit of That

Physics 306 Computing Lab 5: A Little Bit of This, A Little Bit of That Physics 306 Computing Lab 5: A Little Bit of This, A Little Bit of That 1. Introduction You have seen situations in which the way numbers are stored in a computer affects a program. For example, in the

More information

Informatica e Sistemi in Tempo Reale

Informatica e Sistemi in Tempo Reale Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 5, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction

More information

Fundamentals of Programming

Fundamentals of Programming Fundamentals of Programming Introduction to the C language Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 29, 2012 G. Lipari (Scuola Superiore Sant Anna) The C language

More information

3/13/2012. ESc101: Introduction to Computers and Programming Languages

3/13/2012. ESc101: Introduction to Computers and Programming Languages ESc101: Introduction to Computers and Programming Languages Instructor: Krithika Venkataramani Semester 2, 2011-2012 The content of these slides is taken from previous course lectures of Prof. R. K. Ghosh,

More information

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 05 I/O statements Printf, Scanf Simple

More information

Lab 1 Introduction to UNIX and C

Lab 1 Introduction to UNIX and C Name: Lab 1 Introduction to UNIX and C This first lab is meant to be an introduction to computer environments we will be using this term. You must have a Pitt username to complete this lab. The doc is

More information

CpSc 1111 Lab 4 Part a Flow Control, Branching, and Formatting

CpSc 1111 Lab 4 Part a Flow Control, Branching, and Formatting CpSc 1111 Lab 4 Part a Flow Control, Branching, and Formatting Your factors.c and multtable.c files are due by Wednesday, 11:59 pm, to be submitted on the SoC handin page at http://handin.cs.clemson.edu.

More information

Getting started with UNIX/Linux for G51PRG and G51CSA

Getting started with UNIX/Linux for G51PRG and G51CSA Getting started with UNIX/Linux for G51PRG and G51CSA David F. Brailsford Steven R. Bagley 1. Introduction These first exercises are very simple and are primarily to get you used to the systems we shall

More information

Lab 1 Introduction to UNIX and C

Lab 1 Introduction to UNIX and C Name: Lab 1 Introduction to UNIX and C This first lab is meant to be an introduction to computer environments we will be using this term. You must have a Pitt username to complete this lab. NOTE: Text

More information

CS102: Standard I/O. %<flag(s)><width><precision><size>conversion-code

CS102: Standard I/O. %<flag(s)><width><precision><size>conversion-code CS102: Standard I/O Our next topic is standard input and standard output in C. The adjective "standard" when applied to "input" or "output" could be interpreted to mean "default". Typically, standard output

More information

Saint Louis University. Intro to Linux and C. CSCI 2400/ ECE 3217: Computer Architecture. Instructors: David Ferry

Saint Louis University. Intro to Linux and C. CSCI 2400/ ECE 3217: Computer Architecture. Instructors: David Ferry Intro to Linux and C CSCI 2400/ ECE 3217: Computer Architecture Instructors: David Ferry 1 Overview Linux C Hello program in C Compiling 2 History of Linux Way back in the day: Bell Labs Unix Widely available

More information

CpSc 111 Lab 3 Integer Variables, Mathematical Operations, & Redirection

CpSc 111 Lab 3 Integer Variables, Mathematical Operations, & Redirection CpSc 111 Lab 3 Integer Variables, Mathematical Operations, & Redirection Overview By the end of the lab, you will be able to: declare variables perform basic arithmetic operations on integer variables

More information

CpSc 1011 Lab 3 Integer Variables, Mathematical Operations, & Redirection

CpSc 1011 Lab 3 Integer Variables, Mathematical Operations, & Redirection CpSc 1011 Lab 3 Integer Variables, Mathematical Operations, & Redirection Overview By the end of the lab, you will be able to: declare variables perform basic arithmetic operations on integer variables

More information

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information Laboratory 2: Programming Basics and Variables Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information 3. Comment: a. name your program with extension.c b. use o option to specify

More information

COMP s1 Lecture 1

COMP s1 Lecture 1 COMP1511 18s1 Lecture 1 1 Numbers In, Numbers Out Andrew Bennett more printf variables scanf 2 Before we begin introduce yourself to the person sitting next to you why did

More information

CENG393 Computer Networks Labwork 1

CENG393 Computer Networks Labwork 1 CENG393 Computer Networks Labwork 1 Linux is the common name given to a large family of operating systems. All Linux-based operating systems are essentially a large set of computer software that are bound

More information

Chapter 2. Editing And Compiling

Chapter 2. Editing And Compiling Chapter 2. Editing And Compiling Now that the main concepts of programming have been explained, it's time to actually do some programming. In order for you to "edit" and "compile" a program, you'll need

More information

Notes By: Shailesh Bdr. Pandey, TA, Computer Engineering Department, Nepal Engineering College

Notes By: Shailesh Bdr. Pandey, TA, Computer Engineering Department, Nepal Engineering College Preparing to Program You should take certain steps when you're solving a problem. First, you must define the problem. If you don't know what the problem is, you can't find a solution! Once you know what

More information

Intermediate Programming, Spring Misha Kazhdan

Intermediate Programming, Spring Misha Kazhdan 600.120 Intermediate Programming, Spring 2017 Misha Kazhdan Outline Unix/Linux command line Basics of the Emacs editor Compiling and running a simple C program Cloning a repository Connecting to ugrad

More information

Hacking C Code - Local Machine

Hacking C Code - Local Machine Hacking C Code - Local Machine For CS department machines, use your LDAP password, and log in with ssh to remote.cs.binghamton.edu (unless you're actually sitting at a Unix machine in one of the labs,

More information

AN INTRODUCTION PROGRAMMING. Simon Long

AN INTRODUCTION PROGRAMMING. Simon Long AN INTRODUCTION & GUI TO PROGRAMMING Simon Long 2 3 First published in 2019 by Raspberry Pi Trading Ltd, Maurice Wilkes Building, St. John's Innovation Park, Cowley Road, Cambridge, CB4 0DS Publishing

More information

Introduction to Linux

Introduction to Linux Introduction to Linux The command-line interface A command-line interface (CLI) is a type of interface, that is, a way to interact with a computer. Window systems, punched cards or a bunch of dials, buttons

More information

Using the Zoo Workstations

Using the Zoo Workstations Using the Zoo Workstations Version 1.86: January 16, 2014 If you ve used Linux before, you can probably skip many of these instructions, but skim just in case. Please direct corrections and suggestions

More information

Getting Started. Excerpted from Hello World! Computer Programming for Kids and Other Beginners

Getting Started. Excerpted from Hello World! Computer Programming for Kids and Other Beginners Getting Started Excerpted from Hello World! Computer Programming for Kids and Other Beginners EARLY ACCESS EDITION Warren D. Sande and Carter Sande MEAP Release: May 2008 Softbound print: November 2008

More information

1. The Mac Environment in Sierra Hall 1242

1. The Mac Environment in Sierra Hall 1242 Wednesday, August 26, 2015 Lab Notes Topics for today The Mac Environment C (and Unix) Notes on C Part 1 Program 1 1. The Mac Environment in Sierra Hall 1242 a. Turning on the Mac If the Mac is in sleep

More information

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG 1 Notice Reading Assignment Chapter 1: Introduction to Java Programming Homework 1 It is due this coming Sunday

More information

1. The Mac Environment in SIE 1222

1. The Mac Environment in SIE 1222 Friday, September 1, 2017 Lab Notes Topics for today The Mac Environment C (and Unix) Notes on C Part 1 Program 1 1. The Mac Environment in SIE 1222 a. Turning on the Mac If the Mac is in sleep mode you

More information

last time in cs recitations. computer commands. today s topics.

last time in cs recitations. computer commands. today s topics. last time in cs1007... recitations. course objectives policies academic integrity resources WEB PAGE: http://www.columbia.edu/ cs1007 NOTE CHANGES IN ASSESSMENT 5 EXTRA CREDIT POINTS ADDED sign up for

More information

CSC111 Computer Science II

CSC111 Computer Science II CSC111 Computer Science II Lab 1 Getting to know Linux Introduction The purpose of this lab is to introduce you to the command line interface in Linux. Getting started In our labs If you are in one of

More information

Introduction: The Unix shell and C programming

Introduction: The Unix shell and C programming Introduction: The Unix shell and C programming 1DT048: Programming for Beginners Uppsala University June 11, 2014 You ll be working with the assignments in the Unix labs. If you are new to Unix or working

More information

Computer Programming: Skills & Concepts (CP) Variables and ints

Computer Programming: Skills & Concepts (CP) Variables and ints CP Lect 3 slide 1 25 September 2017 Computer Programming: Skills & Concepts (CP) Variables and ints C. Alexandru 25 September 2017 CP Lect 3 slide 2 25 September 2017 Week 1 Lectures Structure of the CP

More information

Practical Session 0 Introduction to Linux

Practical Session 0 Introduction to Linux School of Computer Science and Software Engineering Clayton Campus, Monash University CSE2303 and CSE2304 Semester I, 2001 Practical Session 0 Introduction to Linux Novell accounts. Every Monash student

More information

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language 1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC

More information

Week 1: Introduction to R, part 1

Week 1: Introduction to R, part 1 Week 1: Introduction to R, part 1 Goals Learning how to start with R and RStudio Use the command line Use functions in R Learning the Tools What is R? What is RStudio? Getting started R is a computer program

More information

APPM 2460 Matlab Basics

APPM 2460 Matlab Basics APPM 2460 Matlab Basics 1 Introduction In this lab we ll get acquainted with the basics of Matlab. This will be review if you ve done any sort of programming before; the goal here is to get everyone on

More information

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet.

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet. Mr G s Java Jive #2: Yo! Our First Program With this handout you ll write your first program, which we ll call Yo. Programs, Classes, and Objects, Oh My! People regularly refer to Java as a language that

More information

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals

More information

printf( Please enter another number: ); scanf( %d, &num2);

printf( Please enter another number: ); scanf( %d, &num2); CIT 593 Intro to Computer Systems Lecture #13 (11/1/12) Now that we've looked at how an assembly language program runs on a computer, we're ready to move up a level and start working with more powerful

More information

CMSC 201 Fall 2016 Lab 09 Advanced Debugging

CMSC 201 Fall 2016 Lab 09 Advanced Debugging CMSC 201 Fall 2016 Lab 09 Advanced Debugging Assignment: Lab 09 Advanced Debugging Due Date: During discussion Value: 10 points Part 1: Introduction to Errors Throughout this semester, we have been working

More information

Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators

Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators Operators Overview Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators Operands and Operators Mathematical or logical relationships

More information

Integer Representation. Variables. Real Representation. Integer Overflow/Underflow

Integer Representation. Variables. Real Representation. Integer Overflow/Underflow Variables Integer Representation Variables are used to store a value. The value a variable holds may change over its lifetime. At any point in time a variable stores one value (except quantum computers!)

More information

Computer Science 322 Operating Systems Mount Holyoke College Spring Topic Notes: C and Unix Overview

Computer Science 322 Operating Systems Mount Holyoke College Spring Topic Notes: C and Unix Overview Computer Science 322 Operating Systems Mount Holyoke College Spring 2010 Topic Notes: C and Unix Overview This course is about operating systems, but since most of our upcoming programming is in C on a

More information

EL2310 Scientific Programming

EL2310 Scientific Programming (yaseminb@kth.se) Overview Overview Roots of C Getting started with C Closer look at Hello World Programming Environment Discussion Basic Datatypes and printf Schedule Introduction to C - main part of

More information

15-122: Principles of Imperative Computation

15-122: Principles of Imperative Computation 15-122: Principles of Imperative Computation Lab 0 Navigating your account in Linux Tom Cortina, Rob Simmons Unlike typical graphical interfaces for operating systems, here you are entering commands directly

More information

If Statements, For Loops, Functions

If Statements, For Loops, Functions Fundamentals of Programming If Statements, For Loops, Functions Table of Contents Hello World Types of Variables Integers and Floats String Boolean Relational Operators Lists Conditionals If and Else Statements

More information

CSC209. Software Tools and Systems Programming. https://mcs.utm.utoronto.ca/~209

CSC209. Software Tools and Systems Programming. https://mcs.utm.utoronto.ca/~209 CSC209 Software Tools and Systems Programming https://mcs.utm.utoronto.ca/~209 What is this Course About? Software Tools Using them Building them Systems Programming Quirks of C The file system System

More information

Lab: Supplying Inputs to Programs

Lab: Supplying Inputs to Programs Steven Zeil May 25, 2013 Contents 1 Running the Program 2 2 Supplying Standard Input 4 3 Command Line Parameters 4 1 In this lab, we will look at some of the different ways that basic I/O information can

More information

Arithmetic Expressions in C

Arithmetic Expressions in C Arithmetic Expressions in C Arithmetic Expressions consist of numeric literals, arithmetic operators, and numeric variables. They simplify to a single value, when evaluated. Here is an example of an arithmetic

More information

Hello World! Computer Programming for Kids and Other Beginners. Chapter 1. by Warren Sande and Carter Sande. Copyright 2009 Manning Publications

Hello World! Computer Programming for Kids and Other Beginners. Chapter 1. by Warren Sande and Carter Sande. Copyright 2009 Manning Publications Hello World! Computer Programming for Kids and Other Beginners by Warren Sande and Carter Sande Chapter 1 Copyright 2009 Manning Publications brief contents Preface xiii Acknowledgments xix About this

More information

The Very Basics of the R Interpreter

The Very Basics of the R Interpreter Chapter 2 The Very Basics of the R Interpreter OK, the computer is fired up. We have R installed. It is time to get started. 1. Start R by double-clicking on the R desktop icon. 2. Alternatively, open

More information

EXCEL BASICS: MICROSOFT OFFICE 2007

EXCEL BASICS: MICROSOFT OFFICE 2007 EXCEL BASICS: MICROSOFT OFFICE 2007 GETTING STARTED PAGE 02 Prerequisites What You Will Learn USING MICROSOFT EXCEL PAGE 03 Opening Microsoft Excel Microsoft Excel Features Keyboard Review Pointer Shapes

More information

CpSc 111 Lab 5 Conditional Statements, Loops, the Math Library, and Redirecting Input

CpSc 111 Lab 5 Conditional Statements, Loops, the Math Library, and Redirecting Input CpSc Lab 5 Conditional Statements, Loops, the Math Library, and Redirecting Input Overview For this lab, you will use: one or more of the conditional statements explained below scanf() or fscanf() to read

More information

Part II Composition of Functions

Part II Composition of Functions Part II Composition of Functions The big idea in this part of the book is deceptively simple. It s that we can take the value returned by one function and use it as an argument to another function. By

More information

SU2017. LAB 1 (May 4/9) Introduction to C, Function Declaration vs. Definition, Basic I/O (scanf/printf, getchar/putchar)

SU2017. LAB 1 (May 4/9) Introduction to C, Function Declaration vs. Definition, Basic I/O (scanf/printf, getchar/putchar) SU2017. LAB 1 (May 4/9) Introduction to C, Function Declaration vs. Definition, Basic I/O (scanf/printf, getchar/putchar) 1 Problem A 1.1 Specification Write an ANSI-C program that reads input from the

More information

Parallel Programming Pre-Assignment. Setting up the Software Environment

Parallel Programming Pre-Assignment. Setting up the Software Environment Parallel Programming Pre-Assignment Setting up the Software Environment Author: B. Wilkinson Modification date: January 3, 2016 Software The purpose of this pre-assignment is to set up the software environment

More information

CSC105, Introduction to Computer Science I. Introduction. Perl Directions NOTE : It is also a good idea to

CSC105, Introduction to Computer Science I. Introduction. Perl Directions NOTE : It is also a good idea to CSC105, Introduction to Computer Science Lab03: Introducing Perl I. Introduction. [NOTE: This material assumes that you have reviewed Chapters 1, First Steps in Perl and 2, Working With Simple Values in

More information

Spectroscopic Analysis: Peak Detector

Spectroscopic Analysis: Peak Detector Electronics and Instrumentation Laboratory Sacramento State Physics Department Spectroscopic Analysis: Peak Detector Purpose: The purpose of this experiment is a common sort of experiment in spectroscopy.

More information

Intro to HPC Exercise

Intro to HPC Exercise Intro to HPC Exercise Lab Exercise: Introduction to HPC The assumption is that you have already tested your Amazon Web Service Elastic Compute Cloud (EC2) virtual machines chosen for the LCI hands on exercises.

More information

ESSENTIALS LEARN CODE WITH PROGRAM WITH THE WORLD S MOST POPULAR LANGUAGE ON. Raspberry Pi YOUR. Written by Simon Long

ESSENTIALS LEARN CODE WITH PROGRAM WITH THE WORLD S MOST POPULAR LANGUAGE ON. Raspberry Pi YOUR. Written by Simon Long ESSENTIALS LEARN C PROGRAM WITH THE WORLD S CODE WITH MOST POPULAR LANGUAGE ON Raspberry Pi YOUR Written by Simon Long TO SUBSCRIBE TODAY AND RECEIVE A FREE PI ZERO W Subscribe in print for 12 months today

More information

Matlab for FMRI Module 1: the basics Instructor: Luis Hernandez-Garcia

Matlab for FMRI Module 1: the basics Instructor: Luis Hernandez-Garcia Matlab for FMRI Module 1: the basics Instructor: Luis Hernandez-Garcia The goal for this tutorial is to make sure that you understand a few key concepts related to programming, and that you know the basics

More information

Preprocessor Directives

Preprocessor Directives C++ By 6 EXAMPLE Preprocessor Directives As you might recall from Chapter 2, What Is a Program?, the C++ compiler routes your programs through a preprocessor before it compiles them. The preprocessor can

More information

Science One CS : Getting Started

Science One CS : Getting Started Science One CS 2018-2019: Getting Started Note: if you are having trouble with any of the steps here, do not panic! Ask on Piazza! We will resolve them this Friday when we meet from 10am-noon. You can

More information

Linux Systems Administration Shell Scripting Basics. Mike Jager Network Startup Resource Center

Linux Systems Administration Shell Scripting Basics. Mike Jager Network Startup Resource Center Linux Systems Administration Shell Scripting Basics Mike Jager Network Startup Resource Center mike.jager@synack.co.nz These materials are licensed under the Creative Commons Attribution-NonCommercial

More information

3. Simple Types, Variables, and Constants

3. Simple Types, Variables, and Constants 3. Simple Types, Variables, and Constants This section of the lectures will look at simple containers in which you can storing single values in the programming language C++. You might find it interesting

More information

EL2310 Scientific Programming

EL2310 Scientific Programming Lecture 7: Introduction to C (pronobis@kth.se) Overview Overview Lecture 7: Introduction to C Wrap Up Basic Datatypes and printf Branching and Loops in C Constant values Wrap Up Lecture 7: Introduction

More information

CpSc 1111 Lab 4 Formatting and Flow Control

CpSc 1111 Lab 4 Formatting and Flow Control CpSc 1111 Lab 4 Formatting and Flow Control Overview By the end of the lab, you will be able to: use fscanf() to accept a character input from the user and print out the ASCII decimal, octal, and hexadecimal

More information

Slide Set 2. for ENCM 335 in Fall Steve Norman, PhD, PEng

Slide Set 2. for ENCM 335 in Fall Steve Norman, PhD, PEng Slide Set 2 for ENCM 335 in Fall 2018 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary September 2018 ENCM 335 Fall 2018 Slide Set 2 slide

More information

Get JAVA. I will just tell you what I did (on January 10, 2017). I went to:

Get JAVA. I will just tell you what I did (on January 10, 2017). I went to: Get JAVA To compile programs you need the JDK (Java Development Kit). To RUN programs you need the JRE (Java Runtime Environment). This download will get BOTH of them, so that you will be able to both

More information

The C language. Introductory course #1

The C language. Introductory course #1 The C language Introductory course #1 History of C Born at AT&T Bell Laboratory of USA in 1972. Written by Dennis Ritchie C language was created for designing the UNIX operating system Quickly adopted

More information

CS50 Supersection (for those less comfortable)

CS50 Supersection (for those less comfortable) CS50 Supersection (for those less comfortable) Friday, September 8, 2017 3 4pm, Science Center C Maria Zlatkova, Doug Lloyd Today s Topics Setting up CS50 IDE Variables and Data Types Conditions Boolean

More information

CS451 - Assignment 8 Faster Naive Bayes? Say it ain t so...

CS451 - Assignment 8 Faster Naive Bayes? Say it ain t so... CS451 - Assignment 8 Faster Naive Bayes? Say it ain t so... Part 1 due: Friday, Nov. 8 before class Part 2 due: Monday, Nov. 11 before class Part 3 due: Sunday, Nov. 17 by 11:50pm http://www.hadoopwizard.com/what-is-hadoop-a-light-hearted-view/

More information

Computers and Computation. The Modern Computer. The Operating System. The Operating System

Computers and Computation. The Modern Computer. The Operating System. The Operating System The Modern Computer Computers and Computation What is a computer? A machine that manipulates data according to instructions. Despite their apparent complexity, at the lowest level computers perform simple

More information

Using GitHub to Share with SparkFun a

Using GitHub to Share with SparkFun a Using GitHub to Share with SparkFun a learn.sparkfun.com tutorial Available online at: http://sfe.io/t52 Contents Introduction Gitting Started Forking a Repository Committing, Pushing and Pulling Syncing

More information

C Introduction Lesson Outline

C Introduction Lesson Outline Outline 1. Outline 2. hello_world.c 3. C Character Set 4. C is Case Sensitive 5. Character String Literal Constant 6. String Literal Cannot Use Multiple Lines 7. Multi-line String Literal Example 8. Newline

More information

Introduction to C Programming

Introduction to C Programming Introduction to C Programming Digital Design and Computer Architecture David Money Harris and Sarah L. Harris 2- C Chapter :: Topics Introduction to C Why C? Example Program Compiling and running a

More information

CSC209. Software Tools and Systems Programming. https://mcs.utm.utoronto.ca/~209

CSC209. Software Tools and Systems Programming. https://mcs.utm.utoronto.ca/~209 CSC209 Software Tools and Systems Programming https://mcs.utm.utoronto.ca/~209 What is this Course About? Software Tools Using them Building them Systems Programming Quirks of C The file system System

More information

Lesson 1: Writing Your First JavaScript

Lesson 1: Writing Your First JavaScript JavaScript 101 1-1 Lesson 1: Writing Your First JavaScript OBJECTIVES: In this lesson you will be taught how to Use the tag Insert JavaScript code in a Web page Hide your JavaScript

More information

Room 3P16 Telephone: extension ~irjohnson/uqc146s1.html

Room 3P16 Telephone: extension ~irjohnson/uqc146s1.html UQC146S1 Introductory Image Processing in C Ian Johnson Room 3P16 Telephone: extension 3167 Email: Ian.Johnson@uwe.ac.uk http://www.csm.uwe.ac.uk/ ~irjohnson/uqc146s1.html Ian Johnson 1 UQC146S1 What is

More information

Introduction to Programming

Introduction to Programming CHAPTER 1 Introduction to Programming Begin at the beginning, and go on till you come to the end: then stop. This method of telling a story is as good today as it was when the King of Hearts prescribed

More information

CMPT 102 Introduction to Scientific Computer Programming. Input and Output. Your first program

CMPT 102 Introduction to Scientific Computer Programming. Input and Output. Your first program CMPT 102 Introduction to Scientific Computer Programming Input and Output Janice Regan, CMPT 102, Sept. 2006 0 Your first program /* My first C program */ /* make the computer print the string Hello world

More information

notice the '' you must have those around character values, they are not needed for integers or decimals.

notice the '' you must have those around character values, they are not needed for integers or decimals. C programming for the complete newbie Hello there im Krisis you may have seen me on irc.hackersclub.com. Well I thought it was about time to write an article like everyone else. But unlike many others

More information

Slide Set 1. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

Slide Set 1. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary Slide Set 1 for ENCM 339 Fall 2016 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary September 2016 ENCM 339 Fall 2016 Slide Set 1 slide 2/43

More information

CS 231 Data Structures and Algorithms, Fall 2016

CS 231 Data Structures and Algorithms, Fall 2016 CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard

More information

Chapter 2. Basics of Program Writing

Chapter 2. Basics of Program Writing Chapter 2. Basics of Program Writing Programs start as a set of instructions written by a human being. Before they can be used by the computer, they must undergo several transformations. In this chapter,

More information

27-Sep CSCI 2132 Software Development Lab 4: Exploring bash and C Compilation. Faculty of Computer Science, Dalhousie University

27-Sep CSCI 2132 Software Development Lab 4: Exploring bash and C Compilation. Faculty of Computer Science, Dalhousie University Lecture 4 p.1 Faculty of Computer Science, Dalhousie University CSCI 2132 Software Development Lab 4: Exploring bash and C Compilation 27-Sep-2017 Location: Goldberg CS Building Time: Wednesday, 16:05

More information

How to approach a computational problem

How to approach a computational problem How to approach a computational problem A lot of people find computer programming difficult, especially when they first get started with it. Sometimes the problems are problems specifically related to

More information

PRINCIPLES OF OPERATING SYSTEMS

PRINCIPLES OF OPERATING SYSTEMS PRINCIPLES OF OPERATING SYSTEMS Tutorial-1&2: C Review CPSC 457, Spring 2015 May 20-21, 2015 Department of Computer Science, University of Calgary Connecting to your VM Open a terminal (in your linux machine)

More information

CpSc 1011 Lab 5 Conditional Statements, Loops, ASCII code, and Redirecting Input Characters and Hurricanes

CpSc 1011 Lab 5 Conditional Statements, Loops, ASCII code, and Redirecting Input Characters and Hurricanes CpSc 1011 Lab 5 Conditional Statements, Loops, ASCII code, and Redirecting Input Characters and Hurricanes Overview For this lab, you will use: one or more of the conditional statements explained below

More information

CS 220: Introduction to Parallel Computing. Beginning C. Lecture 2

CS 220: Introduction to Parallel Computing. Beginning C. Lecture 2 CS 220: Introduction to Parallel Computing Beginning C Lecture 2 Today s Schedule More C Background Differences: C vs Java/Python The C Compiler HW0 8/25/17 CS 220: Parallel Computing 2 Today s Schedule

More information

ENCM 335 Fall 2018 Lab 2 for the Week of September 24

ENCM 335 Fall 2018 Lab 2 for the Week of September 24 page 1 of 8 ENCM 335 Fall 2018 Lab 2 for the Week of September 24 Steve Norman Department of Electrical & Computer Engineering University of Calgary September 2018 Lab instructions and other documents

More information

ECGR 4101/5101, Fall 2016: Lab 1 First Embedded Systems Project Learning Objectives:

ECGR 4101/5101, Fall 2016: Lab 1 First Embedded Systems Project Learning Objectives: ECGR 4101/5101, Fall 2016: Lab 1 First Embedded Systems Project Learning Objectives: This lab will introduce basic embedded systems programming concepts by familiarizing the user with an embedded programming

More information

Math 25 and Maple 3 + 4;

Math 25 and Maple 3 + 4; Math 25 and Maple This is a brief document describing how Maple can help you avoid some of the more tedious tasks involved in your Math 25 homework. It is by no means a comprehensive introduction to using

More information

Teacher Activity: page 1/9 Mathematical Expressions in Microsoft Word

Teacher Activity: page 1/9 Mathematical Expressions in Microsoft Word Teacher Activity: page 1/9 Mathematical Expressions in Microsoft Word These instructions assume that you are familiar with using MS Word for ordinary word processing *. If you are not comfortable entering

More information

Intro. Scheme Basics. scm> 5 5. scm>

Intro. Scheme Basics. scm> 5 5. scm> Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if

More information

Software Lesson 1 Outline

Software Lesson 1 Outline Software Lesson 1 Outline 1. Software Lesson 1 Outline 2. What is Software? A Program? Data? 3. What are Instructions? 4. What is a Programming Language? 5. What is Source Code? What is a Source File?

More information

Chapter 4. Unix Tutorial. Unix Shell

Chapter 4. Unix Tutorial. Unix Shell Chapter 4 Unix Tutorial Users and applications interact with hardware through an operating system (OS). Unix is a very basic operating system in that it has just the essentials. Many operating systems,

More information

NCMail: Microsoft Outlook User s Guide

NCMail: Microsoft Outlook User s Guide NCMail: Microsoft Outlook 2003 Email User s Guide Revision 1.0 11/10/2007 This document covers how to use Microsoft Outlook 2003 for accessing your email with the NCMail Exchange email system. The syntax

More information

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #03 The Programming Cycle

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #03 The Programming Cycle Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #03 The Programming Cycle (Refer Slide Time: 00:22) Once we are understood what algorithms are, we will start

More information

EXCEL BASICS: MICROSOFT OFFICE 2010

EXCEL BASICS: MICROSOFT OFFICE 2010 EXCEL BASICS: MICROSOFT OFFICE 2010 GETTING STARTED PAGE 02 Prerequisites What You Will Learn USING MICROSOFT EXCEL PAGE 03 Opening Microsoft Excel Microsoft Excel Features Keyboard Review Pointer Shapes

More information