Programming In
Total Page:16
File Type:pdf, Size:1020Kb
Programming in CS 8251 Programming inPress C As per Anna University R17 syllabus ReemaUniversity Thareja Assistant Professor Department of Computer Science Shyama Prasad Mukherji College for Women University of Delhi Oxford © Oxford University Press. All rights reserved. 3 Oxford University Press is a department of the University of Oxford. It furthers the University’s objective of excellence in research, scholarship, and education by publishing worldwide. Oxford is a registered trade mark of Oxford University Press in the UK and in certain other countries. Published in India by Oxford University Press Ground Floor, 2/11, Ansari Road, Daryaganj, New Delhi 110002, India © Oxford University Press 2018 The moral rights of the author/s have been asserted. First published in 2018 All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, without the prior permission in writing of Oxford University Press, or as expressly permitted by law, by licence, or under terms agreed with the appropriate reprographics rights organization. Enquiries concerning reproduction outside the scope of the above should be sent to the Rights Department, Oxford University Press, at the address above. You must not circulate this work in any other Pressform and you must impose this same condition on any acquirer. ISBN-13: 978-0-19-948552-9 ISBN-10: 0-19-948552-6 Typeset in Times New Roman by Pee-Gee Graphics, New Delhi Printed in India by Magic International (P) Ltd., Greater Noida Cover image: Nizwa Design / Shutterstock Third-party website addressesUniversity mentioned in this book are provided by Oxford University Press in good faith and for information only. Oxford University Press disclaims any responsibility for the material contained therein. Oxford © Oxford University Press. All rights reserved. Features of the Book Comprehensive Coverage Introduction to Arrays Programming The book provides comprehensive Introduction to C Strings coverage of C programming constructs. Decision Control and Pointers Looping Statements Functions Files Notes Note These elements highlight the important The printf and returnPress statements have been indented terms and concepts discussed in each or moved away from the left side. This is done to make the chapter. code more readable. 1. Find out the output of the following program. Programming Examples #include <stdio.h> int main() As many as 250 C programs are { Universityincluded, which demonstrate the int a, b; applicability of the concepts learned. printf("\n Enter two four digit numbers : "); scanf("%2d %4d", &a, &b); printf("\n The two numbers are : %d and %d", a, b); return 0; } Oxford Output Enter two four digit numbers : 1234 5678 The two numbers are : 12 and 34 12 Programming in C ∑ New data and functions can be easily added as and when In the forthcoming chapters, we are going to study C required. programming language which supports both procedural as ∑ Follows a bottom-up approach for problem solving. well as structured programming. Points to Remember POINTS TO REMEMBER A list of key topics at the end of ∑ A computer has two parts—computer hardware which from a storage device to main memory, where they can be does all the physical work and computer software which executed. each chapter helps readers to tells the hardware what to do and how to do it. ∑ The fourth generations of programming languages revise all the important concepts ∑ A program is a set of instructions that are arranged in are: machine language, assembly language, high-level a sequence to guide a computer to find a solution for a language, and very high-level language. explained in the chapter. given problem. The process of writing a program is called ∑ Machine language is the lowest level of programming programming. language that a computer understands. All the instructions ∑ Computer software is written by computer programmers and data values are expressed using 1s and 0s. using a programming language. ∑ Assembly language is a low-level language that uses ∑ Application software is designed to solve a particular symbolic notation to represent machine language problem for users. instructions. ∑ System software represents programs that allow the ∑ Third-generation languages are high-level languages in hardware to run properly. It acts as an interface between which instructions are written in statements like English the hardware of the computer and the application language statements. Each instruction in this language © softwareOxford that Universityusers need to run on Press.the computer. All rightsexpands reserved. into several machine language instructions. ∑ The key role of BIOS is to load and start the operating ∑ Fourth-generation languages are non-procedural system. The code in the BIOS chip runs a series of tests languages in which programmers define only what they called POST (Power On Self Test) to ensure that the system want the computer to do, without supplying all the details devices are working correctly. BIOS is stored on a ROM of how it has to be done. chip built into the system. ∑ Programs written using monolithic programming ∑ Utility software is used to analyse, configure, optimize, languages such as assembly language and BASIC consist and maintain the computer system. of global data and sequential code. ∑ A compiler is a special type of program that transforms ∑ In procedural languages, a program is divided into source code written in a programming language (the subroutines that can access global data. source language) into machine language comprising of ∑ Structured programming employs a top-down approach just two digits—1s and 0s (the target language). The in which the overall program is broken down into separate resultant code in 1s and 0s is known as the object code. modules. ∑ Linker is a program that combines object modules to form ∑ Object-oriented programming treats data as a critical an executable program. element in the program development and restricts its ∑ A loader is a special type of program that copies programs flow freely around the system. EXERCISES Fill in the Blanks 5. ________ transforms the source code into binary 1. ________ tells the hardware what to do and how to do language. it. 6. ________ allows a computer to interact with additional 2. The hardware needs a ________ to instruct what has to hardware devices such as printers, scanners, and video be done. cards. 3. The process of writing a program is called _______. 7. ________ helps in coordinating system resources and 4. ________ is used to write computer software. allows other programs to execute. Glossary GLOSSARY All chapters provide a list of key terms along with their definitions for a quick recapitulation of important terms learned. C Case Study 1: Chapters 2 and 3 Case Studies Select chapters are followed by case We have learnt the basics of programming in C language Roman Numeral Table Pressstudies that show how C can be used and concepts to write decision-making programs, let us now apply our learning to write some useful programs. 1 I 14 XIV 27 XXVII 150 CL to create programs demonstrating 2 II 15 XV 28 XXVIII 200 CC real-life applications. 3 III 16 XVI 29 XXIX 300 CCC ROMAN NUMERALS 4 IV 17 XVII 30 XXX 400 CD Roman numerals are written as combinations of the seven 5 V 18 XVIII 31 XXXI 500 D letters. These letters include: 6 VI 19 XIX 40 XL 600 DC I = 1 C = 100 7 VII 20 XX 50 L 700 DCC 8 VIII 21 XXI 60 LX 800 DCCC V = 5 D = 500 9 IX 22 XXII 70 LXX 900 CM X = 10 M = 1000 10 X 23 XXIII 80 LXXX 1000 M L = 50 11 XI 24 XXIV 90 XC 1600 MDC University Programming Tips Programming Tip: These elements educate readers about If you do not place common programming errors and how a parenthesis after to resolve them. Oxford ‘main’, a compiler error will be generated. Programming Exercises 1. Write a program which deletes all duplicate elements from Programming Exercises the array. Numerous exercises at the end 2. Write a program that tests the equality of two one- of every chapter test the readers’ dimensional arrays. understanding of the concepts 3. Write a program that reads an array of 100 integers. Display learned. all pairs of elements whose sum is 50. © Oxford University Press. All rights reserved. Companion Online Resources for Instructors and Students Companion Site for Higher Education “A Teaching aid for ProfessorsVisit and www.oupinheonline.com a Learning aid for Students” to access both Contents of Companion Site “www.oupinheonline.com”teaching and learning solutions online. The following resources are available to 1 Search By: support the faculty and studentsFeatures: using this book: • Author • Free access via username and password • Title 1 authentication. • ISBN For Faculty • Resources for more than 150 titles and new 2 titles are being added every week. ∑ Solutions4 • ManualResources are developed by Authors 2 Browse by Subjects • 24X7 available 3 ∑ PowerPoint Slides • Unlimited access to read, download or save 1. Biotechnology ∑ C Projects the content (No DRM) 2. Business Management • Non-Subscriber can view the availability of 3. Chemical Engineering the resources For Students 4. Civil Engineering 5 5. Computer Science and IT ∑ Codes of Programming Examples 6. Economics 4 Member Login 7. Electrical Engineering 6 ∑ Multiple Student/InstructorChoice Questions having username and 8. Electronics ∑ Supplementarypassword can Reading login from here Material 9. Engineering General Online Resources available for the following users: 10. Hospitality 11. Life sciences Instructors Students 5 New Instructor Registration: 12. Mechanical Engineering PowerPoint Presentation Web links Press Sign Up for Instructors 13. Media Studies Solutions Manual Projects Teaching Notes Multiple Choice Questions 3 6 New Student Registration: Recent Solutions to Case Studies Scholastic Capability Test Newly Released titles for which and more..