www.apress.com Kalicharan Learn to Program w ith C Learn to Program with C Learn to Program using the Popular C Programming Language — Noel Kalicharan Learn to Program with C B O O K S F O R P R O F E...

Selection logic and if statements


www.apress.com Kalicharan Learn to Program w ith C Learn to Program with C Learn to Program using the Popular C Programming Language — Noel Kalicharan Learn to Program with C B O O K S F O R P R O F E S S I O N A L S B Y P R O F E S S I O N A L S® THE E XPER T ’S VOICE® IN PROGR A MMING Learn to Program with C teaches computer programming to the complete beginner using the native C language. As such, it assumes you have no knowledge whatsoever about programming. The main goal of this book is to teach fundamental programming principles using C, one of the most widely used programming languages in the world today. We discuss only those features and statements in C that are necessary to achieve our goal. Once you learn the principles well, they can be applied to any language. If you are worried that you are not good at high-school mathematics, don’t be. It is a myth that you must be good at mathematics to learn programming. C is considered a ‘modern’ language even though its roots date back to the 1970s. Originally, C was designed for writing ‘systems’ programs—things like operating systems, editors, compilers, assemblers and input/output utility programs. But, today, C is used for writing all kinds of applications as well—word processing programs, spreadsheet programs, database management programs, accounting programs, games, robots, embedded systems/electronics (i.e., Arduino), educational so� ware—the list is endless. • How to get started with programming using the C language • How to use the basics of C • How to program with sequence, selection and repetition logic • How to work with characters • How to work with functions • How to use arrays Shelve in: Programming Languages/ANSI C User level: Beginning SOURCE CODE ONLINE9 781484 213728 ISBN 978-1-4842-1372-8ISBN 978-1-4842-1372-8 Learn to Program with C Noel Kalicharan Learn to Program with C Copyright © 2015 by Noel Kalicharan This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Exempted from this legal reservation are brief excerpts in connection with reviews or scholarly analysis or material supplied specifically for the purpose of being entered and executed on a computer system, for exclusive use by the purchaser of the work. Duplication of this publication or parts thereof is permitted only under the provisions of the Copyright Law of the Publisher’s location, in its current version, and permission for use must always be obtained from Springer. Permissions for use may be obtained through RightsLink at the Copyright Clearance Center. Violations are liable to prosecution under the respective Copyright Law. ISBN-13 (pbk): 978-1-4842-1372-8 ISBN-13 (electronic): 978-1-4842-1371-1 Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Managing Director: Welmoed Spahr Lead Editor: Steve Anglin Technical Reviewer: Rohan Walia Editorial Board: Steve Anglin, Louise Corrigan, Jonathan Gennick, Robert Hutchinson, Michelle Lowman, James Markham, Susan McDermott, Matthew Moodie, Jeffrey Pepper, Douglas Pundick, Ben Renow-Clarke, Gwenan Spearing Coordinating Editor: Mark Powers Copy Editor: Karen Jameson Compositor: SPi Global Indexer: SPi Global Artist: SPi Global Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation. For information on translations, please e-mail [email protected], or visit www.apress.com. Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales–eBook Licensing web page at www.apress.com/bulk-sales. Any source code or other supplementary materials referenced by the author in this text is available to readers at www.apress.com/9781484213728. For detailed information about how to locate your book’s source code, go to www.apress.com/source-code/. Readers can also access source code at SpringerLink in the Supplementary Material section for each chapter. mailto:[email protected] www.springeronline.com mailto:[email protected] www.apress.com www.apress.com/bulk-sales www.apress.com/9781484213728 www.apress.com/source-code/ To my daughters Anushka Nikita and Saskia Anyara v Contents at a Glance About the Author �����������������������������������������������������������������������������������������������������xv About the Technical Reviewer �������������������������������������������������������������������������������xvii Acknowledgments ��������������������������������������������������������������������������������������������������xix Preface �������������������������������������������������������������������������������������������������������������������xxi ■Chapter 1: Elementary Programming Concepts ���������������������������������������������������� 1 ■Chapter 2: C – The Basics ������������������������������������������������������������������������������������ 23 ■Chapter 3: Programs with Sequence Logic ��������������������������������������������������������� 47 ■Chapter 4: Programs with Selection Logic ���������������������������������������������������������� 65 ■Chapter 5: Programs with Repetition Logic ��������������������������������������������������������� 91 ■Chapter 6: Characters ���������������������������������������������������������������������������������������� 141 ■Chapter 7: Functions ����������������������������������������������������������������������������������������� 165 ■Chapter 8: Arrays ���������������������������������������������������������������������������������������������� 197 ■Chapter 9: Searching, Sorting, and Merging ����������������������������������������������������� 243 ■Chapter 10: Structures �������������������������������������������������������������������������������������� 279 Index ��������������������������������������������������������������������������������������������������������������������� 307 vii Contents About the Author �����������������������������������������������������������������������������������������������������xv About the Technical Reviewer �������������������������������������������������������������������������������xvii Acknowledgments ��������������������������������������������������������������������������������������������������xix Preface �������������������������������������������������������������������������������������������������������������������xxi ■Chapter 1: Elementary Programming Concepts ���������������������������������������������������� 1 1.1 Programs, Languages, and Compilers ........................................................................ 1 1.2 How a Computer Solves a Problem ............................................................................ 3 1.2.1 Define the Problem ........................................................................................................................ 3 1.2.2 Analyze the Problem ...................................................................................................................... 4 1.2.3 Develop an Algorithm to Solve the Problem .................................................................................. 4 1.2.4 Write the Program for the Algorithm .............................................................................................. 6 1.2.5 Test and Debug the Program ......................................................................................................... 8 1.2.6 Document the Program..................................................
Jun 02, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here