Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Computer Programming II
List of Instructors
Ms. K. V. Santhilata Dr. Lucy J. Gudino Ms. Aruna G. Mr. R.K. Roul Mr. Mahadev Gawas Mr. Debajyoti Ghosh Mr. Durgesh Samant Mr. Gaurav Sharma Ms. Tejaswini V. S. (Chamber A-420)
Reference Books
(R1) Kernighan and Ritchie. The C Programming Language. Pearson Education. 2nd Edition (R2) Yale N. Patt, and Sanjay J. Patel. Introduction to Computing Systems (From Bits and Gates to C and Beyond). McGraw Hill International Edition 2001. (R3) E.Balagurusamy, Programming in ANSI C, Tata McGrawHill, Edition 2
Motivation
What is Problem Solving?
Problem reformulation Shaping
Course Handout
Part II
Course Description
C Programming Language (12)
To learn and understand fundamental high-level programming constructs such as functions, arrays,structures, pointers and also to learn how to organize data using dynamically allocated storage.
Course Description
Analysis and design of algorithms (12)
To understand the role of algorithms, their analysis and design
Course Description
Non-linear Data Storage (3)
To understand the organization of non-linear data storage, their analysis and design.
Evaluation Scheme
Component Test I Test II Lab sessions Mode Closed Book Closed Book ----2 hours 3 hours Duration 60 minutes 60 Minutes Weightage 20% 20% 10% 10% 40%
Todays topic
Introduction
Computer
What is a computer?
is a complex system is a programmable device must be able to process data must be able to store data must be able to move data must be able to control above three functions
Computer
CPU
Input ALU Output
CU
Memory
Von-Neumann Concept
Data and instructions are stored in single read-write memory The contents of this memory are addressable by location, without regard to the type of data contained there Execution occurs in a sequential fashion from one instruction to the next
Programming
A sequence of steps For each step, an arithmetic or logical operation is done Software Algorithm Hardwired program: Program in the form of hardware
Computer Programming I
Bits and Bytes Number Systems and Number representations Digital logic structures as basic building blocks of a digital computer.
Logical gates Combinational circuits Sequential circuits
Computer Programming I
Concept of an instruction and the concept of Programming using instructions. Problem solving using computers : Concept of Algorithms Problem solving using C programming Language
Computer Programming I
C is often called a middle level computer languageWhy?
Is it because C is less powerful, harder to use, or less developed than a high level language such as BASIC or Pascal or it imply that C has the cumbersome nature of assembly language Actual reason : it combines the best elements of high level language and assembly language
Computer Programming I
C programming Language ..
Data types Control structures Decision making Storage Functions Arrays
Example1
main() { int a = 300, b, c = 100; if ( a >= 400 ) b = 300; c = 200; printf(\n%d %d, b, c); }
Example1
main() { int a = 300, b, c = 100; if ( a >= 400 ) b = 300; c = 200; printf(\n%d %d, b, c); }
Example 2
main() { int x = 10, y = 20; if(x = y) printf(\nx and y are equal); else printf(\nx and y are not equal); }
Note.
TRUE non-zero value FALSE zero value
Example 3
main() { int x = 3; float y = 3.0; if ( x == y) printf(\nx and y are equal); else printf(\nx and y are not equal); }
Example 3(1)
main() { Type int x = 3, z; Casting float y = 3.5; z = y; if ( x == z) printf(\nx and y are equal); else printf(\nx and y are not equal); }
Example 4
main() { int i = 4, j = -1, k = 0, w, x, y, z; w = i || j || k; x = i && j && k; y = i || j && k; z = i && j || k; printf(w = %d, x = %d, y = %d, z = %d, w,x,y,z); w = true }
x = false y = true z = true
Bitwise Operators
Operator
~ >>
Meaning
Ones Complement Right shift
<<
& |
Left shift
Bitwise AND Bitwise OR
Bitwise XOR
Example 5
main() { int x; for( x = 1; x <= 5 ; printf(\n%d,x)); x++; }
for loop
Start Initialize
False
Test
True
Stop
Example 6
main() { int x =0; for ( ; x ; ) printf(\n welcome); }
Example 7
main() { int x = 10, y, z; y = --x; z = x--; printf(\n%d %d %d, x,y,z); }
x=8 y=9 z=9
Example 8
main() { float x = 3.0; switch(x){ case 1.0: printf(one); break; case 2.0: printf(Two); break; default: printf(Three); } }
Points to be noted
The switch expression must be an integer type Case labels must be constants or constant expressions Case labels must be unique Case labels must end with colon The break statement transfers the control out of the switch statement The break statement is optional
Points to be noted
The default statement is optional There can be at most one default label The default may be placed anywhere but usually placed at the end It is permitted to nest switch statements
Example 9
Example 10
Example 11
Example 12
Example 13