Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

Computer Programming Using C
Computer Programming Using C
Computer Programming Using C
Ebook550 pages4 hours

Computer Programming Using C

Rating: 0 out of 5 stars

()

Read preview

About this ebook

This book covers the syllabus of C Programming of MAKAUT, RTU , GBTU and other universities.This book is beneficial for B.Tech all streams, BCA and MCA.

LanguageEnglish
PublisherAmazon
Release dateOct 5, 2016
ISBN9781479173181
Computer Programming Using C

Read more from Ramkrishna Ghosh

Related authors

Related to Computer Programming Using C

Related ebooks

Teaching Methods & Materials For You

View More

Related articles

Reviews for Computer Programming Using C

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    Computer Programming Using C - Ramkrishna Ghosh

    Basic Computation and The Principles of Computer programming

    ––––––––
    Debasis Das, Ramkrishna Ghosh  
    ––––––––

    About the Authors

    Ramkrishna Ghosh is  an Assistant Professor in IT, Haldia Institute of Technology,Haldia Under West Bengal University of Technology. Formerly, he was Assistant Professor in CSE, College of Science and Engineering under SR Group of Institutions (SRGI), Jhansi and Assistant Professor in IT, Bhartiya Institute of Engineering and Technology,Sikar under Rajasthan Technical University(RTU). He was a lecturer in Rani Birla Girls’ College under Calcutta University at the beginning of his teaching career. His experience of a total of 7.5 years includes a stint as a Software Developer. He qualified in GATE 2007 on paper IT with score 438 and an all India rank of 180.

    His areas of interest include Programming Languages, Networking, Software Engineering, Operating System and Object Oriented Technology.  He has authored several research papers and books.

    Debasis Das has a BE degree in Electronics Engineering from Jadavpur University. He completed his M Tech in EE, Computer Science Major from IIT, Kanpur. He worked for the first 16 years in DRDO and next 25 years or so in the software industry, with several multinationals, catering to clients from USA, Europe, Japan and China. He has been teaching in engineering colleges for the last 5 years. He worked as Associate Professor and head of CSE and IT departments in Mallabhum Institute of technology. He became Dean, Academic Affairs- CS programs in SR Group of institutions  for their B Tech and M Tech programs in CSE and IT, and MCA programs.

    Dedicated to my parents  - Ramkrishna Ghosh

    To Mamata, Jia and Udayan - Debasis Das

    Preface

    First Edition

    ––––––––

    This book covers the contents of Computer programming and Computer science course for the 1st year B.Tech Computer Science and Information technology courses of the West Bengal University of technology.  Most of the other technology universities around the country have a similar courses as well. Basic computer skills, particularly programming skill are essential for students of technology. All engineering students have a growing need for grooming in programming concepts as computers become an essential tool for study, research and other professional activities. They will need this skill not only for rest of their B Tech programs but also for higher studies, and during their working life. This book includes solved questions to illustrate the concepts, wherever necessary. Clear understanding of the concepts illustrated here, will be useful not only for doing well in examinations but also in technical interviews with recruiters.The study material in this book is divided into 13 chapters covering the prescribed syllabus. Students of other technology universities with a similar courses can also benefit from this book.

    While every care has been taken to ensure there are no mistakes in the book, some errors might have can slipped through. It is always possible to improve the content, and we welcome and appreciate any suggestions to help us improve the course material. Comments pointing out errors are also welcome.

    Ramkrishna Ghosh (email-ramkr.ghosh@gmail.com) and Debasis Das (ddas15847@gmail.com)

    Contents 

    1. Basics of Computers and Number System

    1.1 Introduction

    1.2 Fundamentals Of Computers

    1.2.1 History of Computers

    1.2.1 Types of Computers and their Definitions

    1.2.3 Different Generations of computers

    1.2.4 Different types of memory in a computer system.

    1.2.5 Components of a Digital Computer

    1.2.6 Modern Generation computers

    1.2.7 Input and Output devices

    1.2.8 Software And Hardware

    1.3 Operating system and Translators

    1.3.1 Definition

    1.3.2 Functions of Operating System

    1.3.3 Evolution of Operating System

    1.3.4 MS-DOS

    1.3.5 MS-WINDOWS

    1.3.6 UNIX

    1.3.7 LINUX

    1.3.8 Translators: Compiler,Interpreter and Assembler

    1.3.9 Differences between Compiler and Interpreter.

    1.4 Algorithm and Flowchart

    1.4.1 Definition

    1.4.2 Components Of Flowchart

    1.4.3 Difference between Algorithm and Flowchart

    1.4.4 Examples on algorithm and Flowchart

    1.4.5 Pseudocode

    1.5 Introduction to Programming Language

    1.5.1 Low Level Languages

    1.5.2 High Level languages

    1.6 Programming Environment

    1.7  Top Down and Stepwise Refinement

    1.8 Structured Programming

    1.9 Logic Gates

    1.10 Number System

    ––––––––

    2. C Fundamentals

    2.1 Introduction of C

    2.2 Features of C

    2.3 Advantages of C

    2.4 Disadvantages of C

    2.5 Program Structure

    2.6 C Compilation Process

    2.7 Keywords in C

    2.8 Constants and Variables

    2.9 Data Types in C

    2.10 Input/Output Functions in C

    3. Operators And Expressions in C

    3.1 Introduction

    3.2 Types of Operators

    3.2.1 Arithmetic

    3.2.2 Unary

    3.2.3 Relational

    3.2.4 Logical

    3.2.5 Conditional

    3.2.6 Bitwise

    3.2.7 Special

    3.2.8 Increment & Decrement

    3.2.9 Assignment

    3.2.10 Size of Operator

    3.3 Operator Precedence and Associativity

    3.4 Type Conversion

    4. Input and Output operations in C

    4.1 Introduction

    4.2 Unformatted Input and Output

    4.3 Formatted Input and Output

    ––––––––

    5. Conditional Program Execution

    5.1 Introduction

    5.2 If And Switch Statement

    5.3 Break, Continue, Goto Statement and exit() function

    5.4 Program Loops and Iteration

    5.4.1 Use of For Loop

    5.4.2 Use of While Loop

    5.4.3 Use of Do While Loop

    5.5 Modular Programming

    6. Functions

    6.1 Introduction

    6.1 Structure of C Function

    6.3 Function Prototype

    6.4 Scope and Visibility in a Function

    6.5 Function with Return Statement

    6.6 Function calling Mechanism

    6.7 Recursion

    6.8 Storage Classes in C

    ––––––––

    7. Array

    7.1 Introduction

    7.2 Definition and Declaration

    7.3 Manipulation Array Elements

    7.4 Using two dimensional Arrays

    8. Structures

    8.1 Introduction

    8.2 Definition and Declaration

    8.3 Why Structure is used?

    8.4 Structure Initialization

    8.5 Accessing Structure Elements

    8.6 Arrays of Structures

    8.7 Structure within Structure

    8.8 Structure and Pointer

    8.9 Structure program using typedef

    8.10 Passing Structure to a Function

    8.11 Difference between array and structure

    8.12 Union

    8.13 Difference between union and structure

    8.14 Bit Field

    8.15 Enumeration

    9. Pointer 

    9.1 Introduction

    9.2 Uses of Pointer

    9.3 Declaration and Initialization

    9.4 Pointer Expression And Pointer Arithmetic

    9.5 Pointer to Array

    9.6 Pointer and Structure

    9.7 Pointer and Functions

    9.8 Void Pointer

    10. Dynamic Memory Allocation

    10.1 Introduction

    10.2 Memory Allocation Process

    10.3 Linked List

    10.4 Application of Linked List

    10.5 Stack

    10.6 Application of Stack

    11. Searching And Sorting

    11.1 Searching

    11.2 Sorting

    12. String Handling in C

    12.1 Introduction

    12.2 String Declaration and Initialization

    12.3 Reading and Writing Strings

    12.4 String Handling Functions

    12.5 Command Line Arguments

    12.6 Math functions

    13. File Handling in C

    13.1 File

    13.2 File Operation

    14. Standard C Preprocessor

    14.1 Definition

    14.2 Types

    14.2.1 Macros

    14.2.2 Conditional Compilation

    14.2.3 File Inclusion

    Chapter-1

    Basics of Computers and Number System

    Objectives

    After going through this chapter the learner will be able to understand:

    1) the history of Computers,different types of Computers, various generations of Computers, components of a Digital Computer and modern generation computers.

    2) the fundamentals of Computers, definition, functions, and types of Operating Systems.

    3) types of memory in a Computer System, Software, Hardware.

    4) definition and types of Operating Systems, and types of translators.

    5) algorithms and flowcharts, types of Programming Language, Programing Environment and Structured Programming.

    6) Number System in detail.

    7) Solved Examples, Summary, Exercise to improve skills.

    1.1 Introduction

    Computers are machines that perform tasks or calculations  according to a set of instructions or programs. The first fully  electronic computers, introduced in the 1940s, were huge  machines that required teams of people to operate. Compared to those early machines, today's computers are amazing.Not only are they thousands of times faster, they can fit on your desk, on your lap, or even in your pocket.

    Computers work through an interaction of hardware and software.Hardware refers to the parts of a computer that you  can see and touch, including the case and everything inside it.The most important piece of hardware is a tiny rectangular chip inside your computer called the central processing unit (CPU), or microprocessor. It's the brain of your computer—the part that translates instructions and performs calculations. Hardware items  such as your monitor, keyboard, mouse, printer, and other  components are often called hardware devices, or devices.

    Software refers to the instructions, or programs, that tell the  hardware what to do. A word-processing program that you can  use to write letters on your computer is a type of software. The operating system (OS) is software that manages your computer and the devices connected to it. Windows is a well-known operating system.

    Modern computers possess certain characteristics and abilities.They can:

    i) Perform complex and repetitive calculations rapidly and accurately.

    ii) Store large amount of data and information for subsequent manipulations

    iii) Compare items and make decisions

    iv)Provide information to the user in many different forms.

    v) Receive and display audio and video signals.

    vi) Automatically correct or modify the parameters of a system under control.

    These capabilities of computers have enabled us to use them for a variety of tasks. Application areas can be broadly classified into the following major categories

    ––––––––

    1. Data processing (commercial use)

    2. Numerical computing (scientific use)

    3. Text processing (office and educational use)

    4. Message Communication (e-mail)

    5. Image Processing (animation and industrial use)

    6. Voice recognition (multimedia).

    1.2 Fundamentals of Computers

    1.2.1 History of Computers

    One of the earliest machines designed to assist people in calculations was the abacus which is still being used some 5000 years after its invention.

    In 1642 Blaise Pascal (a famous French mathematician) invented an adding machine based on mechanical gears in which numbers were represented by the cogs on the wheels. Englishman, Charles Babbage, invented in the 1830's a Difference Engine made out of brass and pewter rods and gears, and also designed a further device which he called an Analytical Engine. His design contained the five key characteristics of modern computers:-

    1.  An input device

    2.  Storage for numbers waiting to be processed

    3.  A processor or number calculator

    4.  A unit to control the task and the sequence of its calculations

    5.  An output device

    Augusta Ada Byron (later Countess of Lovelace), an associate of Babbage, became the first computer programmer.

    An American, Herman Hollerith, developed (around 1890) the first electrically driven device. It utilised punched cards and metal rods which passed through the holes to close an electrical circuit and thus caused a counter to advance. This machine was able to complete the calculation of the 1890 U.S. census in 6 weeks compared with 7 1/2 years for the 1880 census which was manually counted.

    In 1936 Howard Aiken of Harvard University convinced Thomas Watson of IBM to invest $1 million in the development of an electromechanical version of Babbage's analytical engine. The Harvard Mark 1 was completed in 1944 and was 8 feet high and 55 feet long.

    At about the same time (the late 1930's) John Atanasoff of Iowa State University and his assistant Clifford Berry built the first digital computer that worked electronically, the ABC (Atanasoff-Berry Computer). This machine was basically a small calculator.

    In 1943, as part of the British war effort, a series of vacuum tube based computers (named Colossus) were developed to crack German secret codes. The Colossus Mark 2 series (pictured) consisted of 2400 vacuum tubes.

    Fig. Vacuum tube based computers

    John Mauchly and J. Presper Eckert of the University of Pennsylvania developed these ideas further by proposing a huge machine consisting of 18,000 vacuum tubes. ENIAC (Electronic Numerical Integrator And Computer) was born in 1946. It was a huge machine with a huge power requirement and two major disadvantages. Maintenance was extremely difficult as the tubes broke down regularly and had to be replaced, and there was a serious problem with overheating as well. The most important limitation, however, was that every time a new task needed to be performed the machine need to be rewired. In other words programming was carried out with a soldering iron.

    In the late 1940's John von Neumann (at the time a special consultant to the ENIAC team) developed the EDVAC (Electronic Discrete Variable Automatic Computer) which pioneered the stored program concept. This allowed programs to be read into the computer and so gave birth to the age of general-purpose computers.

    1.2.2 Types Of Computers and their Definitions

    Computer- A computer can be defined as a programmable electronic device that can perform mathematical and logical calculations, processing data in accordance with a predefined program of instructions.

    Computers can be broadly classified into two categories-

    1) Analog

    2) Digital

    1) Analog Computer - An analog computer is a form of computer that uses the continuously-changeable aspects of physical phenomena such as electrical, mechanical, or hydraulic quantities to model the problem being solved. it is a computer in which numerical data are represented by measurable physical variables, such as electrical voltage.

    Analog computers are especially useful in the simulation and evaluation of dynamic situations, such as the flight of a space capsule or the changing weather patterns over a certain area. The key component of the analog computer is the operational amplifier, and the computer's capacity is determined by the number of amplifiers it contains.

    Advantages

    i) Parallel (and real-time) operation—many signal values can be computed simultaneously

    ii) Computation can be done for some applications without the requirement for transducers to convert the inputs/outputs to/from digital electronic form.

    iii) It is relatively simple to design

    Disadvantages

    i) The effects of random noise can make signal loss and distortion impossible to recover

    2) Digital Computer

    In digital computers, input is in the form numbers, letters and special characters. It can store and process the input and give the output in the same form, as numbers, letters or special characters. The capabilities of digital computers are adding, subtracting, multiplying, dividing and comparing.

    There are also computers called hybrid computers, which are a combination of the capabilities of digital computers and analog computers. Hybrid computers are used in areas where input is required in analog form and the output in digital form.

    1.2.3 Different Generations of computers

    ––––––––

    The history of computer development is often referred to in reference to the different generations of computing devices. Each generation of computers is characterized by a major technological development that fundamentally changed the way computers operate, resulting in increasingly smaller, cheaper, more powerful, and more efficient and reliable devices.

    First Generation (1940-1956) Vacuum Tubes

    The first computers used vacuum tubes for circuitry and magnetic drums for memory, and were often enormous, taking up entire rooms. They were very expensive to operate and in addition to using a great deal of electricity, generated a lot of heat, which was often the cause of malfunctions.

    First generation computers relied on machine language, the lowest-level programming language understood by computers, to perform operations, and they could only solve one problem at a time. Input was based on punched cards and paper tape, and output was displayed on printouts.

    The UNIVAC and ENIAC computers are examples of first-generation computing devices. The UNIVAC was the first commercial computer delivered to a business client, the U.S. Census Bureau in 1951.

    Second Generation (1956-1963) Transistors

    Transistors replaced vacuum tubes and ushered in the second generation of computers. The transistor was invented in 1947 but did not see widespread use in computers until the late 1950s. The transistor was far superior to the vacuum tube, allowing computers to become smaller, faster, cheaper, more energy-efficient, and more reliable than their first-generation predecessors. Though the transistor still generated a great deal of heat that subjected the computer to damage, it was a vast improvement over the vacuum tube. Second-generation computers still relied on punched cards for input and printouts for output.

    Second-generation computers moved from cryptic binary machine language to symbolic, or assembly, languages, which allowed programmers to specify instructions in words. High-level programming languages were also being developed at this time, such as early versions of COBOL and FORTRAN. These were also the first computers that stored their instructions in their memory, which moved from a magnetic drum to magnetic core technology.

    The first computers of this generation were developed for the atomic energy industry.

    Third Generation (1964-1971) Integrated Circuits

    The development of the integrated circuit was the hallmark of the third generation of computers. Transistors were miniaturized and placed on siliconchips, calledsemiconductors, which drastically increased the speed and efficiency of computers.

    Instead of punched cards and printouts, users interacted with third generation computers throughkeyboards andmonitors andinterfaced with anoperating system, which allowed the device to run many differentapplications at one time with a central program that monitored the memory. Computers for the first time became accessible to a mass audience because they were smaller and cheaper than their predecessors.

    Fourth Generation (1971-Present) Microprocessors

    The microprocessor brought the fourth generation of computers, as thousands of integrated circuits were built onto a single silicon chip. What in the first generation filled an entire room could now fit in the palm of the hand. The Intel 4004 chip, developed in 1971, located all the components of the computer—from the central processing unit and memory to input/output controls—on a single chip.

    In 1981 IBM introduced its first computer for the home user, and in 1984 Apple introduced the Macintosh. Microprocessors also moved out of the realm of desktop computers and into many areas of life as more and more everyday products began to use microprocessors.

    As these small computers became more powerful, they could be linked together to form networks, which eventually led to the development of the Internet. Fourth generation computers also saw the development

    Enjoying the preview?
    Page 1 of 1