Beginning C Programming for Engineers CSCI1190 - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

Beginning C Programming for Engineers CSCI1190

Description:

If you are not sure, look up in Appendix C. Operator Precedence Charts, p1193. Decrement ... Multiplication. Subtraction. Addition. Arithmetic Operators: An ... – PowerPoint PPT presentation

Number of Views:35
Avg rating:3.0/5.0
Slides: 16
Provided by: gang3
Category:

less

Transcript and Presenter's Notes

Title: Beginning C Programming for Engineers CSCI1190


1
Beginning C Programming for Engineers (CSCI-1190)
  • Instructor Gang Chen (cheng3_at_rpi.edu)
  • Office Hour Thursday 2-4pm (or by appointment)
  • Office Lally 9A
  • Webpage www.cs.rpi.edu/cheng3/teaching/1190

2
Basic Computer Model
CPU
Input
Output
Memory
Instructions Data
Von Neumann Architecture
3
Programming Languages
1300042774 1400593419 1200274027
Machine Languages
LOAD A ADD B STORE C
Assembly Languages
CAB
High-Level Languages
4
Creating Programs
C libaray
hello.o
compile
hello
hello.c
Link
Edit
Source File (High-Level Languages)
Object File (Machine Languages)
Executable
gcc o hello hello.c
nedit hello.c
5
Unix Commands
6
Hello, World
  • / Hello, world program /
  • include ltstdio.hgt
  • int main()
  • printf("hello, ")
  • printf("world\n")
  • return 0
  • Editing xemacs hw.c or nedit hw.c or vi hw.c
  • Compiling gcc Wall o hello hw.c
  • Executing hello

7
Basic Programming Concepts
  • Comment To explain what the program is for and
    why it is the way it is.
  • Preprocessing Done before the program is
    compiled.
  • To include header files containing information
    about C libraries
  • Statement A line of code that tells computer to
    perform some action. Always ended with a
    semicolon().
  • Invoking functions
  • Function A module often consisting of a set of
    statements.
  • Two functions in the hello world program main,
    printf

8
In Class Exercise 1-1
  • Escape Sequences are used to control printf to do
    something other than printing characters.
  • Modify the hello world program to try out various
    escape sequences like
  • \n Newline. Position cursor at the beginning of
    the next line.
  • \t Tab. Move cursor to the next tab stop.
  • \a Alert. Sound the system bell.

9
Arithmetic Operators
  • To form expressions
  • Many statements are merely expressions.
  • Normal order of operations is followed.
    Parentheses can be used.
  • If you are not sure, look up in Appendix C.
    Operator Precedence Charts, p1193

10
Arithmetic Operators An Example
  • / Arithmetic operators /
  • include ltstdio.hgt
  • int main()
  • printf("73d\n",73)
  • printf("7-3d\n",7-3)
  • printf("73d\n",73)
  • printf("7/3d\n",7/3)
  • printf("73d\n",73)
  • printf("7.0/3.0f\n",7.0/3.0)
  • return 0

11
Variables
  • Variable Name for a memory object. Variable
    names must start with letters and contain
    letters, digits, and underscores.
  • a, b, i, j, counter, number_of_points, c1234,
  • Type What the variable represents. Could be of
    integer, floating point number, character,
    string, and many others.
  • int, float, double, char,
  • Declaration Tells compiler about variables and
    their type.
  • int i,j
  • float sum

12
Numeric Types
13
Reading Inputs
  • include ltstdio.hgt
  • int main()
  • float a,b
  • printf("Please input the first
    number\n")
  • scanf("f",a)
  • printf("Please input the second
    number\n")
  • scanf("f",b)
  • printf("abf\n",ab)
  • printf("a-bf\n",a-b)
  • printf("abf\n",ab)
  • printf("a/bf\n",a/b)

14
Assignment
  • / Arithmetic operators /
  • include ltstdio.hgt
  • int main()
  • int a,c
  • int b4
  • a3
  • cab
  • printf(Sum d d -gt d\n,a,b,c)
  • ab--
  • prinf(Now ad and bd\n,a,b)
  • return 0

15
In-Class Exercise 1-2
  • Write a program to calculate the average of three
    floating point numbers, namely 2.3, 3.4, 4.5.
  • Using scanf function
  • Using assignment
Write a Comment
User Comments (0)
About PowerShow.com