Está en la página 1de 39

TA C 252

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)

Text and Reference Books


Text Books
(T1) Jery R Hanly, Elliot B Koffman., Problem Solving and Program Design in C, Pearson Education, 5th Edition, 2007. (T2) Dromey, R G., How to Solve it by Computer, Eastern Economy Ed, Prentice Hall 2002.

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

How do we solve problems? How do computers help in problem solving?

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.

Data Structures (8)


To understand the basic concepts of Data structures such as linked list, queue, stacks etc.

Course Description
Analysis and design of algorithms (12)
To understand the role of algorithms, their analysis and design

Recursive Definitions (3)


To understand the basics of recursive definitions: recursive data and recursive procedures.

Course Description
Non-linear Data Storage (3)
To understand the organization of non-linear data storage, their analysis and design.

Advanced Program Structuring(3)


To understand advanced concepts and techniques in program structuring: higher order functions and objects.

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%

Practical online Open Book test Comprehensive Closed Book

What is expected from you


100% attendance Coming in time to class/lab/tutorial Finishing home work given in the class/tutorial class Clarifying doubts with any of the faculty members Collecting answer sheets on the day of distribution of papers Not to indulge in malpractice Mobile phones switched off in the class / lab

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

Logical structure of a digital computer.

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

C allows the manipulation of bits, bytes and addresses C is portable


Portability means that it is easy to adapt software written for one type of computer or operating system to another type

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

Body of Loop Increment

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

También podría gustarte