33
Ceng 230 Programming with C Tansel Dökeroğlu Computer Engineering Department Spring 2015 [email protected]

Ceng 230 Programming with C Tansel Dökeroğlu Computer Engineering Department Spring 2015 [email protected]

Embed Size (px)

Citation preview

Page 1: Ceng 230 Programming with C Tansel Dökeroğlu Computer Engineering Department Spring 2015 tanseldoker@yahoo.com.tr

Ceng 230 Programming with C

Tansel Dökeroğlu

Computer Engineering DepartmentSpring 2015

[email protected]

Page 2: Ceng 230 Programming with C Tansel Dökeroğlu Computer Engineering Department Spring 2015 tanseldoker@yahoo.com.tr

Web pages Official web site of the courseceng230.ceng.metu.edu.tr

My personal C lecture web site:http://www.ceng.metu.edu.tr/~e1451970/

Page 3: Ceng 230 Programming with C Tansel Dökeroğlu Computer Engineering Department Spring 2015 tanseldoker@yahoo.com.tr

"All the high-school students will be taught the fundamentals of computer technology will

become proficient in binary arithmetic and will be trained to perfection in the use of the computer

languages “

Science fiction writer Isaac Asimov's Predictions For 2014 From in 1960s

Page 4: Ceng 230 Programming with C Tansel Dökeroğlu Computer Engineering Department Spring 2015 tanseldoker@yahoo.com.tr

• COMPUTER

– Device capable of performing computations and making logical decisions– Computers process data under the control of sets of instructions called computer programs

• Hardware– Various devices comprising a computer– Keyboard, screen, mouse, disks, memory, CD-ROM, printer, and processing units

• Software– Programs that run on a computer– Microsoft Windows, Microsoft Office, Internet Explorer

Page 5: Ceng 230 Programming with C Tansel Dökeroğlu Computer Engineering Department Spring 2015 tanseldoker@yahoo.com.tr

Conceptual Structure of a Computer System

Page 6: Ceng 230 Programming with C Tansel Dökeroğlu Computer Engineering Department Spring 2015 tanseldoker@yahoo.com.tr

CPU (Central Processing Unit)• Process and manipulate information stored in memory.

• It can be divided into two units: CU (Control Unit) and ALU (Arithmetic Logic Unit)

• CU coordinates activities of the computer and controls other devices of computer.

• ALU processes arithmetical and logical instructions.

Page 7: Ceng 230 Programming with C Tansel Dökeroğlu Computer Engineering Department Spring 2015 tanseldoker@yahoo.com.tr

Bit and Byte

A bit is a single numeric value, either '1' or '0', that encodes a single unit of digital information.

A byte is a sequence of bits; usually eight bits equal one byte.

Byte = 8 bitsKiloByte (KB) = 1,024 BytesMegaBytes (MB) = 1,024 KBGigaByte (GB) = 1,024 MB TeraByte (TB) = 1,024 GB

Page 8: Ceng 230 Programming with C Tansel Dökeroğlu Computer Engineering Department Spring 2015 tanseldoker@yahoo.com.tr

Memory• Store information (data + instructions)• A sequence of memory cells.

• Store, retrieve, update– changing the pattern of 0 and 1s in memory cells– copying these patterns into some internal registers

• Stored information in memory is volatile.

Page 9: Ceng 230 Programming with C Tansel Dökeroğlu Computer Engineering Department Spring 2015 tanseldoker@yahoo.com.tr
Page 10: Ceng 230 Programming with C Tansel Dökeroğlu Computer Engineering Department Spring 2015 tanseldoker@yahoo.com.tr

• Hardware can only deal with binary digits, 0 and 1.• Must represent all numbers, integers or floating

point, positive or negative, by binary digits, called bits.

• Can devise electronic circuits to perform arithmetic operations: add, subtract, multiply and divide, on binary numbers.

Binary System

Page 11: Ceng 230 Programming with C Tansel Dökeroğlu Computer Engineering Department Spring 2015 tanseldoker@yahoo.com.tr

• Decimal system: made of 10 digits, {0,1,2, . . . , 9}

41 = 4×101 + 1×100

255 = 2×102 + 5×101 + 5×100

• Binary system: made of two digits, {0,1}

00101001 = 0×27 + 0×26 + 1×25 + 0×24 +1×23 + 0×22 + 0×21 + 1×20

= 32 + 8 +1 = 4111111111 = 255, largest number with 8

binary digits, 28-1

Binary System

Page 12: Ceng 230 Programming with C Tansel Dökeroğlu Computer Engineering Department Spring 2015 tanseldoker@yahoo.com.tr
Page 13: Ceng 230 Programming with C Tansel Dökeroğlu Computer Engineering Department Spring 2015 tanseldoker@yahoo.com.tr

ASCII Table American Standard Code for Information Interchange

Page 14: Ceng 230 Programming with C Tansel Dökeroğlu Computer Engineering Department Spring 2015 tanseldoker@yahoo.com.tr

History of C• C– Developed by Denis M. Ritchie at AT&T Bell Labs in1972 as a systems programming language– Used to develop UNIX– Used to write modern operating systems– Hardware independent (portable)

• Standardization– Many slight variations of C existed, and were incompatible– Committee formed to create a "unambiguous, machine independent“ definition– Standard created in 1989, updated in 1999

Page 15: Ceng 230 Programming with C Tansel Dökeroğlu Computer Engineering Department Spring 2015 tanseldoker@yahoo.com.tr

Other High-level Languages– C++• Superset of C, and provides object-oriented capabilities

– Java• Create web pages with dynamic and interactive content

– Fortran• Used for scientific and engineering applications

– Cobol• Used to manipulate large amounts of data

– Pascal• Intended for academic use

Page 16: Ceng 230 Programming with C Tansel Dökeroğlu Computer Engineering Department Spring 2015 tanseldoker@yahoo.com.tr

Flow chart of a program (Algorithm)

In mathematics and computer science, an algorithm is a step-by-step procedure for calculations.

Page 17: Ceng 230 Programming with C Tansel Dökeroğlu Computer Engineering Department Spring 2015 tanseldoker@yahoo.com.tr

C language development environment

Page 18: Ceng 230 Programming with C Tansel Dökeroğlu Computer Engineering Department Spring 2015 tanseldoker@yahoo.com.tr

http://www.bloodshed.net/devcpp.html

Devc++ to write C code

Page 19: Ceng 230 Programming with C Tansel Dökeroğlu Computer Engineering Department Spring 2015 tanseldoker@yahoo.com.tr
Page 20: Ceng 230 Programming with C Tansel Dökeroğlu Computer Engineering Department Spring 2015 tanseldoker@yahoo.com.tr
Page 21: Ceng 230 Programming with C Tansel Dökeroğlu Computer Engineering Department Spring 2015 tanseldoker@yahoo.com.tr
Page 22: Ceng 230 Programming with C Tansel Dökeroğlu Computer Engineering Department Spring 2015 tanseldoker@yahoo.com.tr
Page 23: Ceng 230 Programming with C Tansel Dökeroğlu Computer Engineering Department Spring 2015 tanseldoker@yahoo.com.tr
Page 24: Ceng 230 Programming with C Tansel Dökeroğlu Computer Engineering Department Spring 2015 tanseldoker@yahoo.com.tr

Output is : 1

printf( "Welcome to \%d", (3/2) );

Page 25: Ceng 230 Programming with C Tansel Dökeroğlu Computer Engineering Department Spring 2015 tanseldoker@yahoo.com.tr

! exclamation mark

Page 26: Ceng 230 Programming with C Tansel Dökeroğlu Computer Engineering Department Spring 2015 tanseldoker@yahoo.com.tr
Page 27: Ceng 230 Programming with C Tansel Dökeroğlu Computer Engineering Department Spring 2015 tanseldoker@yahoo.com.tr
Page 28: Ceng 230 Programming with C Tansel Dökeroğlu Computer Engineering Department Spring 2015 tanseldoker@yahoo.com.tr
Page 29: Ceng 230 Programming with C Tansel Dökeroğlu Computer Engineering Department Spring 2015 tanseldoker@yahoo.com.tr

Use search engines while studying for errors or sample codes

Page 30: Ceng 230 Programming with C Tansel Dökeroğlu Computer Engineering Department Spring 2015 tanseldoker@yahoo.com.tr

Useful links for C programming

http://www.programmingsimplified.com/c-program-examples

http://www.tutorialspoint.com/cprogramming/

http://www.wikihow.com/Learn-to-Program-in-C

http://www.programiz.com/c-programming/examples

Page 31: Ceng 230 Programming with C Tansel Dökeroğlu Computer Engineering Department Spring 2015 tanseldoker@yahoo.com.tr

Homework

Install BloodshedC++ compiler to your computer

Write a C program that prints your name, surname and mail adress to the screen.

Send the C file to my address ([email protected])

Until next week

Page 32: Ceng 230 Programming with C Tansel Dökeroğlu Computer Engineering Department Spring 2015 tanseldoker@yahoo.com.tr

No cell phones

Page 33: Ceng 230 Programming with C Tansel Dökeroğlu Computer Engineering Department Spring 2015 tanseldoker@yahoo.com.tr

Never give up