Prof. Béat Hirsbrunner Fulvio Frapolli, PhD Student (exercises) Bachelor students : - Major in computer science (first year, 2nd term) - Major in information.

Slides:



Advertisements
Similar presentations
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Advertisements

CSE1301 Computer Programming Lecture 4: C Primitives I.
C workshop Yuli Kaplunovsky - Today - Introduction to C Recommended book: The C programming Language / Kernighan & Ritchie.
流程控制: while loop 迴圈 Test condition Enter loop Yes (non-0) Execute Loop body no exit F=0 F=F+20 … F=F
Imperative Programming Prof. Béat Hirsbrunner Amine Tafat, PhD Student Matthias Buchs and Raphaël Lesceux, Graduate Students Department of Informatics.
0 Arrays (1/2) #include /* count digits, white space, others */ main() { int c, i, nwhite, nother; int ndigit[10]; nwhite = nother = 0; for (i = 0; i
0 Chap. 2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations Imperative Programming, B. Hirsbrunner,
C programming---basic 1 Introduction to C 2 C Fundamentals 3 Formatted Input/Output 4 Expression 5 Selection Statement 6 Loops 7 Basic Types 8 Arrays 9.
A simple C program: Printing a line of text #include main() { printf(“hello, world\n”); } Program output: hello, world.
Introduction to C Language
Computer Science 210 Computer Organization Introduction to C.
C Programming A Modern Approach
CS140: Intro to CS An Overview of Programming in C by Erin Chambers.
1 COMP 2130 Introduction to Computer Systems Computing Science Thompson Rivers University.
By Sidhant Garg.  C was developed between by Dennis Ritchie at Bell Laboratories for use with the Unix Operating System.  Unlike previously.
C Program Design Introduction to C Programming 主講人:虞台文.
Programming I Introduction Introduction The only way to learn a new programming language is by writing programs in it. The first program to.
Outline Symbolic Constants Character Input and Output if … else switch…case.
Compiling & Debugging Quick tutorial. What is gcc? Gcc is the GNU Project C compiler A command-line program Gcc takes C source files as input Outputs.
Engineering Computing I Chapter 1 – Part A A Tutorial Introduction.
Programming Language  C Tutorial Introduction 主講人:虞台文.
1/16 Programski jezik C Vladimir Filipović
How to start Visual Studio 2008 or 2010 (command-line program)
1 COMP 2130 Introduction to Computer Systems Computing Science Thompson Rivers University.
Chapter 7 Formatted input and output. 7.1 introduction Tax: This result is correct; but it would be better Maybe as $13, Make formatting.
1 CSE1301 Computer Programming Lecture 12 Functions (Part 1)
C Program Design Introduction to C Programming 主講人:虞台文.
Basics of Most C++ Programs // Programmer: Clayton Price date: 9/4/ // File: fahr2celc.cpp 03. // Purpose:
CS140: Intro to CS An Overview of Programming in C by Erin Chambers.
CS115 FALL Senem KUMOVA-METİN1 The Fundamental Data Types CHAPTER 3.
1 CSE1301 Computer Programming Lecture 13 Functions (Part 1)
Khalid Rasheed Shaikh Computer Programming Theory 1.
Prof. Béat Hirsbrunner Ammar Halabi, PhD student (exercises) Dani Rotzetter, Master student (exercises) Bachelor students : Major in computer science (3rd.
Introduction to Computer Organization & Systems Topics: Types in C: floating point COMP C Part III.
1 Homework Done the reading? –K&R –Glass Chapters 1 and 2 Applied for cs240? (If not, keep at it!) Gotten a UNIX account? (If not, keep at it!)
Minimal standard C program int main(void) { return 0 ; }
C Homework Write mypaste.c and mycomm.c – mypaste is like paste & mycomm is like comm – Both take two files as arguments – Paste reads a line from each.
Operating System Discussion Section. The Basics of C Reference: Lecture note 2 and 3 notes.html.
Exercise 1 #include int main() { printf(“Hello C Programming!\n”); return 0; } 1.Run your Visual Studio 2008 or Create a new “project” and add.
Chapter 1 Basic C Programming
Computer Programming A simple example /* HelloWorld: A simple C program */ #include int main (void) { printf (“Hello world!\n”); return.
The Cast Operator The cast operator converts explicitly from one data type of an expression to another. For example, if x is of type int, the value of.
CMSC 104, Version 8/061L14AssignmentOps.ppt Assignment Operators Topics Increment and Decrement Operators Assignment Operators Debugging Tips Reading Section.
CPT: Chars/ Computer Programming Techniques Semester 1, 1998 Objectives of these slides: –to look at how C processes characters 4. Character.
1 CSE1301 Computer Programming Lecture 12 Functions (Part 1)
CS113 Introduction to C Instructor: Ioannis A. Vetsikas Lecture 2 : August 28 webpage:
Exercise 2 : Using for loop Repetition (loop) (1)control variable initialization (2)Test Conditon (3)Modification of control variable value order : (1)
KYC - Know your compiler Introduction to GCC
Basic concepts of C++ Presented by Prof. Satyajit De
CSCE 206 Structured Programming in C
Computer Science 210 Computer Organization
Chap. 2. Types, Operators, and Expressions
Computer Programming Techniques Semester 1, 1998
Variable Declarations, Data types, Expressions
Variable Declarations, Data types, Expressions
B. Ramamurthy University at Buffalo
C programming---basic
Embedded Systems Computer-based systems which do not appear to be computers Complexity is hidden from the user Embedded systems are much more common than.
Computer Science 210 Computer Organization
B. Ramamurthy University at Buffalo
B. Ramamurthy University at Buffalo
B. Ramamurthy University at Buffalo
CSI 121 Structured Programming Language Lecture 13 Functions (Part 1)
Govt. Polytechnic,Dhangar
Introduction to C Topics Compilation Using the gcc Compiler
B. Ramamurthy University at Buffalo
Homework Applied for cs240? (If not, keep at it!) 8/10 Done with HW1?
Introduction to C Topics Compilation Using the gcc Compiler
Debugging.
Compile and run c files.
Presentation transcript:

Prof. Béat Hirsbrunner Fulvio Frapolli, PhD Student (exercises) Bachelor students : - Major in computer science (first year, 2nd term) - Major in information systems (first year, 2nd term) - Minor in computer science - Propedeutic in computer science (first year, 2nd term) Imperative Programming University of Fribourg, Department of Informatics Summer term 2007,

1 #include main() { printf("hello, world\n"); } (KR p6) Session 1 (Lecture: 3 hours, Exercises: 1 hour) - 13 March 2007 Hello World % gcc hello.c // Compile hello.c %./a.out // Run a.out % gcc -o hello hello.c // Compile hello.c %./hello // Run hello

2 #include /* Print Fahrenheit-Celsius table for fahr = 0, 20,..., 300 */ main() { int fahr, celsius; int lower, upper, step; lower = 0; /* lower limit of temperature table */ upper = 300; /* upper limit */ step = 20; /* step size */ fahr = lower; while (fahr <= upper) { celsius = 5 * (fahr - 32) / 9; printf("%d\t%d\n", fahr, celsius); fahr = fahr + step; } (KR p9) Variables and Arithmetic Expressions (1)

3 (KR p12) #include /* Print Fahrenheit-Celsius table for fahr = 0, 20,..., 300 */ /* Floating-point version */ main() { float fahr, celsius; int lower, upper, step; lower = 0; /* lower limit of temperature table */ upper = 300; /* upper limit */ step = 20; /* step size */ fahr = lower; while (fahr <= upper) { celsius = (5.0/9.0) * (fahr ); printf("%3.0f %6.1f\n", fahr, celsius); fahr = fahr + step; } Variables and Arithmetic Expressions (2)

4 #include /* print Fahrenheit-Celsius table */ main() { int fahr; for (fahr = 0; fahr <= 300; fahr = fahr + 20) printf("%3d %6.1f\n", fahr, (5.0/9.0)*(fahr-32)); } (KR p13) The For Statement

5 #include #define LOWER 0 /* lower limit of table */ #define UPPER 300 /* upper limit */ #define STEP 20 /* step size */ /* print Fahrenheit-Celsius table */ main() { int fahr; for (fahr = LOWER; fahr <= UPPER; fahr = fahr + STEP) printf("%3d %6.1f\n", fahr, (5.0/9.0)*(fahr-32)); } (KR p15) Symbolic Constants

6 #include /* copy input to output; 1st version */ main() { int c; c = getchar(); while (c != EOF) { putchar(c); c = getchar(); } (KR p16) File Copying (1)

7 #include /* copy input to output; 2nd version */ main() { int c; while ((c = getchar()) != EOF) putchar(c); } (KR p17) File Copying (2)