Beginning C Programming For EngineersCSCI1190 n n Instructor

  • Slides: 11
Download presentation
Beginning C Programming For Engineers(CSCI-1190) n n Instructor: Sunil Upalekar upales@cs. rpi. edu Meets:

Beginning C Programming For Engineers(CSCI-1190) n n Instructor: Sunil Upalekar [email protected] rpi. edu Meets: Monday 8: 00 PM to 9: 50 PM Wednesday 6: 00 PM to 8: 00 PM Office: Thursday 12: 00 PM to 2: 00 PM Webpage: www. cs. rpi. edu/~upales/cprog

Administrative Details n n n No Credit can be taken for this course if

Administrative Details n n n No Credit can be taken for this course if you are taking any other CS course Textbook: “C How To Program” by Deitel and Deitel Course Slides, Inclass problems, Homework's will be available on the Course Website

Algorithms and Programs n n n An Algorithm is a sequence of finite, repeatable,

Algorithms and Programs n n n An Algorithm is a sequence of finite, repeatable, unambiguous steps required to solve a problem The implementation of an algorithm that can run on a computer is called a program Operating Systems, Browsers, Matlab…all are examples of programs

Basic Computer Model Central Processor Input Pentium Hard Drive Secondary Storage Output Ram Main

Basic Computer Model Central Processor Input Pentium Hard Drive Secondary Storage Output Ram Main Memory

Hello World! /* Hello, world program */ #include <stdio. h> int main( ) {

Hello World! /* Hello, world program */ #include <stdio. h> int main( ) { printf(“Hello World!!!"); return ( ) ; } Compile: gcc -Wall hello. c Run: . /a. out

Dissection of hello. c Hello. c Compile Hello. o Compiler(gcc) Program File Object Code

Dissection of hello. c Hello. c Compile Hello. o Compiler(gcc) Program File Object Code Linker a. out Executable

In class Exercise -1 Modify the “Hello World” program to try out various Escape

In class Exercise -1 Modify the “Hello World” program to try out various Escape sequences like: • n: Newline. Position cursor at start of new line • t: Tab. Move cursor to the next tab stop • a: Alert. Sound the system bell

Some Basic Ideas n n Types: Interpretation of data bits in the memory. Example:

Some Basic Ideas n n Types: Interpretation of data bits in the memory. Example: int, float, char Variables: Names for memory objects. May comprise of letters, digits, and other special symbols Declaration: Combination of types and variables. Example: int PI; Definition: Allocating memory for variables. Example: int PI = 3. 14;

Basic Types Int(two bytes) Integer Float(four bytes) Floating Point Character Short/short int Short integer

Basic Types Int(two bytes) Integer Float(four bytes) Floating Point Character Short/short int Short integer Long/long int Long integer Double Long floating point Long double Very long floating point

Program using C types /* Program using basic C types*/ #include <stdio. h> int

Program using C types /* Program using basic C types*/ #include <stdio. h> int main( ) { int a = 1, b = 2, c = 0; c = a + b; printf(“Sum of a and b is: %d“, c); return 0 ; } Compile: gcc -Wall ctype. c Run: . /a. out

In class Exercise - 2 Modify the ctype. c program to calculate the Average

In class Exercise - 2 Modify the ctype. c program to calculate the Average of three floating point numbers, namely 2. 3, 3. 4, 4. 5. Tips: • Floating point variables are declared as “float” • Use an intermediate variable to result of average