Top Banner
Sample Copy. Not For Distribution.
23

Sample Copy. Not For Distribution.released by using the services of self-publishing house. Printed in India Sample Copy. Not For Distribution. iii Computer System and Programming in

Mar 13, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Sample Copy. Not For Distribution.released by using the services of self-publishing house. Printed in India Sample Copy. Not For Distribution. iii Computer System and Programming in

Sample Copy. Not For Distribution.

Page 2: Sample Copy. Not For Distribution.released by using the services of self-publishing house. Printed in India Sample Copy. Not For Distribution. iii Computer System and Programming in

i

Computer System and

Programming in C

Sample Copy. Not For Distribution.

Page 3: Sample Copy. Not For Distribution.released by using the services of self-publishing house. Printed in India Sample Copy. Not For Distribution. iii Computer System and Programming in

ii

Publishing-in-support-of,

EDUCREATION PUBLISHING

RZ 94, Sector - 6, Dwarka, New Delhi - 110075 Shubham Vihar, Mangla, Bilaspur, Chhattisgarh - 495001

Website: www.educreation.in

________________________________________________________________

© Copyright, 2018, Authors

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted, in any form by any means, electronic, mechanical, magnetic, optical, chemical, manual, photocopying, recording or otherwise, without the prior written consent of its writer.

ISBN: 978-1-5457-1886-5

Price: ` 340.00

The opinions/ contents expressed in this book are solely of the authors and do not represent the opinions/ standings/ thoughts of Educreation or the Editors . The book is released by using the services of self-publishing house.

Printed in India

Sample Copy. Not For Distribution.

Page 4: Sample Copy. Not For Distribution.released by using the services of self-publishing house. Printed in India Sample Copy. Not For Distribution. iii Computer System and Programming in

iii

Computer System and

Programming in C

As per the New Syllabus of AKTU

(common to all Branches of engineering)

(First Edition)

By

Merajuddin Asstt. Professor

Department of Information Technology Azad Institute of Engineering and Technology

Lucknow(UP)

Masood Ahmad Asstt. Professor

Department of Information Technology Azad Institute of Engineering and Technology

Lucknow(UP)

Malik Shahzad Ahmad Iqbal Asstt. Professor

Department of Information Technology Azad Institute of Engineering and Technology

Lucknow(UP)

EDUCREATION PUBLISHING (Since 2011)

www.educreation.in

Sample Copy. Not For Distribution.

Page 5: Sample Copy. Not For Distribution.released by using the services of self-publishing house. Printed in India Sample Copy. Not For Distribution. iii Computer System and Programming in

iv

Sample Copy. Not For Distribution.

Page 6: Sample Copy. Not For Distribution.released by using the services of self-publishing house. Printed in India Sample Copy. Not For Distribution. iii Computer System and Programming in

v

Dedicated to Almighty God and Parents Specially

my Mother

Sample Copy. Not For Distribution.

Page 7: Sample Copy. Not For Distribution.released by using the services of self-publishing house. Printed in India Sample Copy. Not For Distribution. iii Computer System and Programming in

vi

Preface ______________________________________________________

“Computer system and programming in C “is designed to

help the engineering, Diploma and MCA students of all Indian universities‟ is structural programming language. This is most

popular and very powerful language. It contains all the

fundamental features that need to be in a programming

language. The idea and the scope emerged from my own

experience in attempting to acquire good understanding of computer concept along with C programming.

If you want to take up programming seriously, you‟ve come

across the right book. For real! This is the book with which you

can make your first steps in programming. It will give a flying start to your long journey into learning modern programming

languages and software development technologies. This book

teaches the fundamental principles and concepts of

programming, which have not changed significantly in the past years. Do not hesitate to read this book even if C is not the

language you would like to pursue. Whatever language you

move on to, the knowledge we will give you here will stick,

because this book will teach you to think like programmers. We will show you and teach you how to write programs for solving

practical algorithmic problems, form the skills in you to come

up with (and implement) algorithms, and use various data

structures. As improbable as it might seem to you, the basic

principles of writing computer programs have not changed all that much in the past 15 years. Programming languages

change, technologies get modernized, integrated development

environments get more and more advanced but the

fundamental principles of programming remain the same. When beginners learn to think algorithmically, and then learn to

divide a problem instinctively into a series of steps to solve it,

as well as when they learn to select the appropriate data

structures and write high-quality programming code that is when they become programmers.

For systematic study, the book has been divided in five

units as per the requirements of the syllabus.

Sample Copy. Not For Distribution.

Page 8: Sample Copy. Not For Distribution.released by using the services of self-publishing house. Printed in India Sample Copy. Not For Distribution. iii Computer System and Programming in

vii

Acknowledgement ______________________________________________________

I would like to express my gratitude to the many people who

saw me through this book; to all those who provided support,

talked things over, read, wrote, offered comments, allowed me to quote their remarks and assisted in the editing, proof

reading and design.

It is obvious that writing a textbook is really a tough task

and in this Endeavour many people have lent their helping hands for the success of this book.

I would like to thank my Father Lt.Mr. Abdul Hai & mother

Mrs. Quadirun Nisa for enabling me to publish this book.

Above all I want to thank my Colleagues, and the rest of my family, who supported and encouraged me in spite of all the

time it took me away from them. It was a long and difficult

journey for them.

Dr.Shafeeq Ahmad Director Azad Institute Of Engineering And Technology, Dr.Imran Khan HOD of

Electrical engineering department Azad institute of engineering

and Technology and Dr.Alka Agarwal Asstt.Professor

BBAU,Lucknow deserve special thanks for their constant

encouragement and motivation.

I am indeed lucky to be associated with Azad group of

institution where lots of support from Mr. Suhail Ahmad

(chairman) and Mr. Jamal Ahmad (vice chairman) and their

nice cooperation.

I would like to thank especially GOD for helping and

guiding us for this book written.

And also thanks our friends, family, for giving us some

ideas and support for this book presentation

Especially thank to publication………….

- Merajuddin (Author)

Sample Copy. Not For Distribution.

Page 9: Sample Copy. Not For Distribution.released by using the services of self-publishing house. Printed in India Sample Copy. Not For Distribution. iii Computer System and Programming in

viii

RCS101/RCS201

Computer System and Programming in C

______________________________________________________

Unit1:

Basics of Computer: Introduction to digital computer, basic

operations of computer, functional components of computer,

Classification of computers.

Introduction to operating system:[DOS, Windows, Linux and

Android] purpose, function, services and types.

Number system: Binary, octal and hexadecimal number

systems, their mutual conversions,

Binary arithmetic.

Basics of programming:

Approaches to Problem Solving, Concept of algorithm and flow

charts,

Types of computer languages:-

Machine Language, Assembly Language and High Level

Language, Concept of Assembler, Compiler, Loader and Linker.

Unit2:

Standard I/O in “C”, Fundamental data types-Character type,

integer, short, long, unsigned, single and double floating point

Storage classes-automatic, register, static and external,

Operators and expression using numeric and relational operators, mixed operands, type Conversion, logical operators,

bit operations, assignment operator, operator precedence and

associatively.

Fundamentals of C programming:

Structure of C program, writing and executing the first C program, Components of C language. Standard I/O in C.

Sample Copy. Not For Distribution.

Page 10: Sample Copy. Not For Distribution.released by using the services of self-publishing house. Printed in India Sample Copy. Not For Distribution. iii Computer System and Programming in

ix

Unit3:

Conditional program execution: Applying if and switch

statements, nesting if and else, use of break and default with switch, program loops and iterations: use of while, do while and

for loops, multiple loop variables, use of break and continue

statements.

Functions: Introduction, types of functions, functions with array, passing values to functions, recursive functions.

Unit 4:

Arrays: Array notation and representation, manipulating array

elements, using multi dimensional arrays. Structure, union, enumerated data types

Unit 5:

Pointers: Introduction, declaration, applications File handling, standard C preprocessors, defining and calling macros,

conditional compilation, passing values to the compiler.

Sample Copy. Not For Distribution.

Page 11: Sample Copy. Not For Distribution.released by using the services of self-publishing house. Printed in India Sample Copy. Not For Distribution. iii Computer System and Programming in

x

RCS151/RCS251

Computer Programming Lab

______________________________________________________

1. WAP that accepts the marks of 5 subjects and finds the sum

and percentage marks obtained by the student.

2. WAP that calculates the Simple Interest and Compound Interest. The Principal , Amount, Rate of Interest and Time are

entered through the keyboard.

3. WAP to calculate the area and circumference of a circle.

4. WAP that accepts the temperature in Centigrade and converts into Fahrenheit using the formula C/5=(F-32)/9.

5. WAP that swaps values of two variables using a third

variable.

6. WAP that checks whether the two numbers entered by the user are equal or not.

7. WAP to find the greatest of three numbers.

8. WAP that finds whether a given number is even or odd.

9. WAP that tells whether a given year is a leap year or not.

10. WAP that accepts marks of five subjects and finds

percentage and prints grades according to the following

criteria:

Between 90-100%--------------Print „A‟

80-90%----------------------------Print „B‟

60-80%---------------------------Print „C‟

Below 60%----------------------Print „D‟

11. WAP that takes two operands and one operator from the

user and perform the operation and prints the result by using Switch statement.

12. WAP to print the sum of all numbers up to a given number.

13. WAP to find the factorial of a given number.

14. WAP to print sum of even and odd numbers from 1 to N numbers.

15. WAP to print the Fibonacci series.

16. WAP to check whether the entered number is prime or not.

Sample Copy. Not For Distribution.

Page 12: Sample Copy. Not For Distribution.released by using the services of self-publishing house. Printed in India Sample Copy. Not For Distribution. iii Computer System and Programming in

xi

17. WAP to find the sum of digits of the entered number.

18. WAP to find the reverse of a number.

19. WAP to print Armstrong numbers from 1 to 100.

20. WAP to convert binary number into decimal number and

vice versa.

21. WAP that simply takes elements of the array from the user

and finds the sum of these elements.

22.WAP that inputs two arrays and saves sum of corresponding

elements of these arrays in third array and prints them.

23. WAP to find the minimum and maximum element of the

array.

24. WAP to search an element in a array using Linear Search.

25. WAP to sort the elements of the array in ascending order

using Bubble Sort technique.

26. WAP to add and multiply two matrices of order nxn.

27. WAP that finds the sum of diagonal elements of a mxn matrix.

28. WAP to implement strlen (), strcat (), strcpy () using the

concept of Functions.

29. Define a structure data type TRAIN_INFO. The type contain Train No.: integer type Train name: string Departure Time:

aggregate type TIME Arrival Time : aggregate type TIME Start

station: string End station : string The structure type Time

contains two integer members: hour and minute. Maintain a train timetable and implement the following operations:

(i)List all the trains (sorted according to train number) that

depart from a particular section.

(ii) List all the trains that depart from a particular station at a

particular time.

(iii) List all he trains that depart from a particular station within

the next one hour of a given time.

(iv) List all the trains between a pair of start station and end

station.

30. WAP to swap two elements using the concept of pointers.

31. WAP to compare the contents of two files and determine

whether they are same or not.

32. WAP to check whether a given word exists in a file or not. If yes then find the number of times it occurs

Sample Copy. Not For Distribution.

Page 13: Sample Copy. Not For Distribution.released by using the services of self-publishing house. Printed in India Sample Copy. Not For Distribution. iii Computer System and Programming in

xii

Table of Contents

Sr. Content Page

1. UNIT -1 1

Basics of computer 2

Introduction 2

Functionalaties 3

Functional components of computer 3

Input unit 4

Central processing unit 5

Memory units 5

Output unit 8

Software 9

Unit measurement 11

Classification of computers 11

Characteristics of computer 15

Block diagram of digital computer and functional units

16

Generations of computer 18

Programming languages 21

Introduction to operating system 25

Types of operating system 27

User interface 27

MS DOS operating system 28

Unix operating system 32

Linux operating system 36

Windows operating system 38

Android operating system 39

Android Evolution 39

problem solving Techniques 41

algorithm 41

Sample Copy. Not For Distribution.

Page 14: Sample Copy. Not For Distribution.released by using the services of self-publishing house. Printed in India Sample Copy. Not For Distribution. iii Computer System and Programming in

xiii

Flowchart 42

Flowchart symbols 43

Number system 48

Conversion 49

Questions 57

2. UNIT -2 65

Basic structure of C-Program 66

Execute a C-Program 68

Program development life cycle 69

Problem Definition 69

Problem Analysis 69

Algorithm Development 70

Coding & Documentation 70

Testing & Debugging 70

Maintenance 70

Designing Approaches 70

Top Down 70

Bottom Up 71

Character Set 72

C-Tokens 72

Keywords 73

Identifiers 73

Constants 74

String 74

Special Characters 74

Operators 74

Escape or white space character 75

Data types 75

Primitive or Fundamental Data types 75

Non Primitive or Derived data type 75

Data types in C, Size & Range 76

Integer data type 76

Character data type 77

Floating data type 77

Sample Copy. Not For Distribution.

Page 15: Sample Copy. Not For Distribution.released by using the services of self-publishing house. Printed in India Sample Copy. Not For Distribution. iii Computer System and Programming in

xiv

Single Floating data type 77

Double Floating data type 77

Array 77

String 77

Structure 77

Union 78

Enum 78

Variable 79

Declarative of variable in C 79

Initialization of variable 79

Scope of variable 80

Operators 81

Arithmetic Operators 82

Relational 83

Logical Operators 85

Bitwise Operators 87

Assignment Operators 88

Condition Operators 91

Special Operators 91

Precedence of Operators 92

Associativity of Operators 92

Output 93

Input 94

Storage Classes 95

Auto storage class 96

Register storage class 96

Static storage class 97

Extern storage class 98

Modifiers 99

Qualifiers 100

Data Type conversion 100

Implicit Type conversion 100

Explicit Type conversion 100

Questions 103

Sample Copy. Not For Distribution.

Page 16: Sample Copy. Not For Distribution.released by using the services of self-publishing house. Printed in India Sample Copy. Not For Distribution. iii Computer System and Programming in

xv

3. UNIT -3 107

Introduction 108

Sequential Statement 108

Decision making Statement/ Conditional

Statement

110

Simple IF Statement 110

IF-ELSE Statement 111

Nested IF-ELSE Statement 113

The ELSE IF ladder or IF- ELSE IF

Statement

116

Switch case Statement 118

Looping Statement / Iterative Statement 120

Types of looping Statements 121

Entry Controlled loops 121

While loop 122

Nested while loop 124

For loop 125

Nested for loop 126

Do-while loop 127

Break Statement 129

Continue Statement 129

GOTO Statement 130

Modular Programming 131

Function 132

Structure of a Function 133

Function Declaration 134

Function Definition 134

Function Call 135

Types of Functions 136

Functions with no arguments and no

return values

137

Functions with arguments and no return values

137

Functions with arguments and return

values

138

Functions with no arguments and return 139

Sample Copy. Not For Distribution.

Page 17: Sample Copy. Not For Distribution.released by using the services of self-publishing house. Printed in India Sample Copy. Not For Distribution. iii Computer System and Programming in

xvi

values

Recursion 140

Why recursion function 140

Questions 144

4. UNIT 4 150

What is an array 151

How to define array 152

How to initialize an array 152

Accessing values in an array 154

Sorting 156

Bubble sort 156

Selection sort 158

Insertion sort 159

Searching 160

Sequential or linear search 160

Binary search 161

Two dimensional array 162

Multidimensional array 163

String 167

Basic operations of staring 168

String handling functions 168

Structures 171

Instances of structure 172

Accessing structure members 173

Structures with array 174

Structures within Structures 175

Unions 178

Difference between Structures and union 178

Declaration of Union 178

Accessing union members 179

Questions 181

5. UNIT -5 189

Pointers 190

Declaration of pointers variable 190

Sample Copy. Not For Distribution.

Page 18: Sample Copy. Not For Distribution.released by using the services of self-publishing house. Printed in India Sample Copy. Not For Distribution. iii Computer System and Programming in

xvii

Initialization of pointer variable 191

Void pointer 192

Null Pointer 192

Function calling methods or parameter

passing mechanism

192

Call by value 192

Call by reference 193

Dynamic memory allocation in C 194

malloc() 194

calloc() 194

free() 195

realloc() 196

The C preprocessor 197

Marco substitution directive 197

File inclusion 198

Condition compilation control directive 199

File 200

Basics of file handling in C 201

C file operations 201

Steps for processing a file 201

Opening a File 203

Closing a File 203

Stack 210

Queue 213

Queue Operation 213

Linked list 214

Types of linked list 214

Questions 217

Program Practices 221

Question Paper 252

Sample Copy. Not For Distribution.

Page 19: Sample Copy. Not For Distribution.released by using the services of self-publishing house. Printed in India Sample Copy. Not For Distribution. iii Computer System and Programming in

xviii

Sample Copy. Not For Distribution.

Page 20: Sample Copy. Not For Distribution.released by using the services of self-publishing house. Printed in India Sample Copy. Not For Distribution. iii Computer System and Programming in

Computer System and Programming in C

1

Unit-1

Sample Copy. Not For Distribution.

Page 21: Sample Copy. Not For Distribution.released by using the services of self-publishing house. Printed in India Sample Copy. Not For Distribution. iii Computer System and Programming in

Computer System and Programming in C

2

Chapter- 1 ______________________________________________________

Introction1, Functionalities of computer, Components of

computer , Software, Unit of Measurement, Classification of

computers, Digital computer block diagram, Evolution of

computer, Generation of computer, Programming

languages, Machine Language, Assembly Language, High Level Language, Programming Languages Environment,

Structured Programming, Translators, Operation system,

DOS UNIX,LINUX, WNIDOWS ANDROID, Problem solving

methods, Algorithm, Flowchart, Number system and conversion, Important Questions

INTRODUCTION

A device, using which computation can be performed is called

computer. For computation, computer takes data and

instructions from user, perform calculation or manipulation on it

and show the result.

“Computer is a multipurpose electronic machine which data

and instruction from user or programmer and processes it

(manipulate or compute) and produce result.”

A computer is an electronic device, operating under the control of instructions stored in its own memory that can accept

data (input), process the data according to specified rules,

produce information (output), and store the information for

future use

Computer Science concepts are relevant to many aspects

of our lives, from explorations in the fields of science and

medicine to digital creations in the fields of art and music. This

course introduces students to the central ideas of computer

science and explores technologies of computing and their impact on society and culture. Students are introduced to web

site design, data investigation and manipulation using

spreadsheets, collaborative on-line tools, and fundamental

computer programming concepts. Students develop

Sample Copy. Not For Distribution.

Page 22: Sample Copy. Not For Distribution.released by using the services of self-publishing house. Printed in India Sample Copy. Not For Distribution. iii Computer System and Programming in

Get Complete Book At Educreation Store

www.educreation.in

Sample Copy. Not For Distribution.

Page 23: Sample Copy. Not For Distribution.released by using the services of self-publishing house. Printed in India Sample Copy. Not For Distribution. iii Computer System and Programming in

Sample Copy. Not For Distribution.