Transcription

Computer ProgrammingTutorial

COMPUTER PROGRAMMING TUTORIALSimply Easy Learning by tutorialspoint.comtutorialspoint.comi

ABOUT THE TUTORIALComputer Prgramming TutorialComputer programming is the act of writing computer programs, which are a sequence of instructionswritten using a Computer Programming Language to perform a specified task by the computer.Computer Programming is fun and easy to learn provided you adopt a proper approach. This tutorial willtake you through simple and practical approach while learning computer programming.AudienceThis tutorial has been prepared for the people who are struggling to learn computer programming butthey are unable to learn it due to lack of proper guidance and approach. I'm confident that aftercompleting this tutorial you will be at a level where you can code in C Programming language and willhave basic understanding of Java and Python programming languages as well and you can continuefurther from that point onwards.If you are completely new to Computer Programming, then my recommendation is to read this tutorialtwice or even thrice. First reading will not give you much idea, but during your second reading, you willstart grasping most of the concepts and you will enjoy while writing great computer programs.PrerequisitesI do not expect much from your as pre-requisites to teach you computer programming but I assume thatat-least you have basic knowledge about computer and its peripherals like keyboard, mouse, screen,printer, etc. If you know more than this like word editor, good typing speed, internet search, etc., then itwill help you a lot while doing your computer programming.Copyright & Disclaimer Notice Allthe content and graphics on this tutorial are the property of tutorialspoint.com. Any content fromtutorialspoint.com or this tutorial may not be redistributed or reproduced in any way, shape, or formwithout the written permission of tutorialspoint.com. Failure to do so is a violation of copyright laws.This tutorial may contain inaccuracies or errors and tutorialspoint provides no guarantee regarding theaccuracy of the site or its contents including this tutorial. If you discover that the tutorialspoint.com siteor this tutorial content contains some errors, please contact us at [email protected] POINTSimply Easy Learning

Table of ContentComputer Prgramming Tutorial . 2Audience . 2Prerequisites . 2Copyright & Disclaimer Notice . 2Programming - Overview. 6What is Computer Program? . 6What is Computer Programming? . 7What Computer Program can do? . 7Who is Computer Programmer? . 8What is Algorithm? . 8Programming - Basics . 9Programming - Environment . 11What is Text Editor? . 12What is Compiler? . 12What is Interpreter? . 13Online Compilation . 14Programming - Basic Syntax . 15Hello World Program in C . 15PROGRAM ENTRY POINT . 15FUNCTIONS. 15COMMENTS. 16WHITESPACES . 16SEMICOLONS. 17PROGRAM EXPLANATION . 17Syntax Error. 18Hello World Program in Java . 18Hello World Program in Python . 18Conclusion . 19Programming – Data Types . 20C & Java Data Types . 21Python Data Types . 21Programming - Variables. 23Creating variables. 23Store values in variables . 24Access stored values in variables. 25Variables in Java . 25Variables in Python. 26TUTORIALS POINTSimply Easy Learning

Programming - Keywords . 27C programming reserved keywords . 28Java programming reserved keywords . 28Python programming reserved keywords . 28Programming - Operators. 30Arithmetic Operators. 30Relational Operators. 31Logical Operators . 33Operators in Java . 33Operators in Python . 34Programming - Decisions . 36if.else statement . 38if.elseif.else statement . 39The switch statement . 40Decisions in Java. 42Decisions in Python . 42Programming - Loops . 43The while Loop . 45The do.while Loop . 46The break statement . 47The continue statement . 48Loops in Java . 49Loops in Python . 49Programming - Numbers . 50Math Operations on Numbers. 51Numbers in Java. 52Numbers in Python . 53Programming - Characters . 55Escape Sequences:. 56Characters in Java. 57Characters in Python . 58Programming - Arrays . 59Create Arrays . 60Initializing Arrays . 60Accessing Array Elements . 60Arrays in Java . 61Arrays (Lists) in Python . 62Programming - Strings . 64Basic String Concepts . 66TUTORIALS POINTSimply Easy Learning

Strings in Java . 66Strings in Python . 67Programming - Functions . 68Defining a Function:. 69Calling a Function: . 70Functions in Java. 70Functions in Python . 71Programming – File I/O . 73Computer Files . 73File Input/Output . 73File Operation Modes . 73Opening Files . 74Closing a File . 74Writing a File. 75Reading a File . 75File I/O in Java. 76File I/O in Python . 77Programming - Summary . 78TUTORIALS POINTSimply Easy Learning

1CHAPTERProgramming - OverviewIassume today is your first day when you heard about computer programming. You are curious to know whatexactly is computer programming? Before you understand what is computer programming, you need to understandwhat is computer program?I'm making an assumption that you know a little about what is computer and how to use it for Internet browsing,Exploring Facebook or Checking e-mail using Gmail, etc.What is Computer Program?A computer program is a sequence of instructions written using a Computer Programming Language to perform aspecified task by the computerI assume, you did not understand what I have written about computer program but let’s see two important terms,which I have used in the above definition: Sequence of instructions Computer Programming LanguageTo understand these terms, consider a situation when someone asks you about how to go to a nearby KFC. Whatexactly do you do to tell him the way to go to KFC?You will use Human Language to tell the way to go to KFC something as follows:First go straight, after half kilometer, take left from the red light and then drive around one kilometer and you will findKFC at the right.Here, you have used English Language to give several steps to be taken to reach to KFC. If they will be followed inthe following sequence, then you will reach KFC:1.2.3.4.5.Go straightDrive half kilometerTake leftDrive around one kilometerSearch for KFC at your right sideNow, try to map the situation with computer program. Above sequence of instructions is actually aHumanProgram written in English Language, which instructs on how to reach to KFC from a given starting point. ThisTUTORIALS POINTSimply Easy Learning

same sequence could have been given in Spanish Language, Hindi Language, Arabic or any other human languageprovided someone, who is asking about the way, knows about such languages.Now, let's go back and try to understand about a computer program, which is a sequence of instructions written in aComputer Language to perform a specified task by the computer. Following is a simple program writtenin Python programming Language:print "Hello, World!"Above computer program instructs computer to print "Hello, World!" on computer screen. A computer program is also called a computer software,