Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Unit1-Inroduction To Basic Coding

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

Introduction to programming

Computer programming is the process of designing and writing computer programs. As a


skill set, it includes a wide variety of different tasks and techniques, but our tutorials are not
intended to teach you everything. Instead, they are meant to provide basic, practical skills to
help you understand and write computer code that reflects things you see and use in the real
world. 

Basic of programming
English is the most popular and well-known Human Language. The English language has its own set
of grammar rules, which has to be followed to write in the English language correctly.

Likewise, any other Human Languages (German, Spanish, Russian, etc.) are made of several elements
like nouns, adjective, adverbs, propositions, and conjunctions, etc. So, just like English, Spanish or
other human languages, programming languages are also made of different elements.

Just like human languages, programming languages also follow grammar called syntax. There are
certain basic program code elements which are common for all the programming languages.

Most important basic elements for programming languages are:

 Programming Environment
 Data Types
 Variables
 Keywords
 Logical and Arithmetical Operators
 If else conditions
 Loops
 Numbers, Characters and Arrays
 Functions
 Input and Output Operations

STEPS FOR PROBLEM SOLVING

What are the six steps of problem solving in C?


Six step guide to help you solve problems
 Step 1: Identify and define the problem. State the problem as clearly as possible.
 Step 2: Generate possible solutions.
 Step 3: Evaluate alternatives.
 Step 4: Decide on a solution.
 Step 5: Implement the solution.
 Step 6: Evaluate the outcome.
Computer Program:
In computing, a program is a specific set of ordered operations for a computer to perform. In
the modern computer that John von Neumann outlined in 1945, the program contains a one-
at-a-time sequence of instructions that the computer follows. Typically, the program is put
into a storage area accessible to the computer.

Algorithm:
What is an Algorithm? Algorithm Basics
The word Algorithm  means ”  A set of finite rules or instructions to be followed in
calculations or other problem-solving operations  ” Or ”  A procedure for solving a
mathematical problem in a finite number of steps that frequently involves recursive
operations”.
Therefore Algorithm refers to a sequence of finite steps to solve a particular problem.

Use of the Algorithms: -

Algorithms play a crucial role in various fields and have many applications. Some of the
key areas where algorithms are used include:
Computer Science: Algorithms form the basis of computer programming and are used to
solve problems ranging from simple sorting and searching to complex tasks such as
artificial intelligence and machine learning.

Control Statements | Control Flow in Java

Compiler executes the code from top to bottom. The statements in the code are executed
according to the order in which they appear. However, Java provides statements that can be
used to control the flow of Java code. Such statements are called control flow statements. It is
one of the fundamental features of Java, which provides a smooth flow of program.

Java provides three types of control flow statements.

1. Decision Making statements


o if statements
o switch statement
2. Loop statements
o do while loop
o while loop
o for loop
o for-each loop
3. Jump statements
o break statement
o continue statement

Decision-Making statements:

As the name suggests, decision-making statements decide which statement to execute and
when. Decision-making statements evaluate the Boolean expression and control the program
flow depending upon the result of the condition provided. There are two types of decision-
making statements in Java, i.e., If statement and switch statement.

1) If Statement:

In Java, the "if" statement is used to evaluate a condition. The control of the program is
diverted depending upon the specific condition. The condition of the If statement gives a
Boolean value, either true or false. In Java, there are four types of if-statements given below.

1. Simple if statement
2. if-else statement
3. if-else-if ladder
4. Nested if-statement

Let's understand the if-statements one by one.

Flowchart In Programming

A flowchart is a diagrammatic representation of an algorithm. A flowchart can be helpful for both

writing programs and explaining the program to others

Symbols Used In Flowchart

Symbol Purpose Description

Indicates the flow of


Flow line logic by connecting
symbols.
Represents the start
Terminal(Stop/Start) and the end of a
flowchart.

Used for input and


Input/Output
output operation.

Used for arithmetic


Processing operations and data-
manipulations.

Used for decision


Decision making between two
or more alternatives.

Used to join different


On-page Connector
flowline

Used to connect the


Off-page Connector flowchart portion on a
different page.
Represents a group of
Predefined
statements performing
Process/Function
one processing task.

Examples of flowcharts in programming

1. Add two numbers entered by the user.

Flowchart to add two numbers

2. Find the largest among three different numbers entered by the user.
Flowchart to find the largest among three numbers.

3. Find all the roots of a quadratic equation ax2+bx+c=0


Flowchart to find roots of a quadratic equation

4. Find the Fibonacci series till term≤1000.


Note: Though flowcharts can be useful for writing and analysing a program,

How to execute algorithms/programs:


What is meant by the IDE?
An integrated development environment (IDE) is a software application that helps
programmers develop software code efficiently. It increases developer productivity by
combining capabilities such as software editing, building, testing, and packaging in an easy-
to-use application.

What is compiler:?
A compiler is a special program that translates a programming language's source code into
machine code, bytecode or another
programming language. The source code is typically written in a high-level, human-readable
language such as Java or C++.
What is interpreter and compiler?
A Compiler takes a program as a whole. An Interpreter takes single lines of a code. Output.
The Compilers generate intermediate machine codes. The Interpreters never generate any
intermediate machine codes.

Types of Compiler

1. Cross Compilers
They produce an executable machine code for a platform but, this platform is not the one on
which the compiler is running.

2. Bootstrap Compilers
These compilers are written in a programming language that they have to compile.

3. Source to source/transcompiler
These compilers convert the source code of one programming language to the source code of
another programming language.

4. Decompiler
Basically, it is not a compiler. It is just the reverse of the compiler. It converts the machine code
into high-level language.

Features of a Compiler

The features are as follows:

 Compilation speed.

 The correctness of machine code.

 The meaning of code should not change.

 Speed of machine code.

 Good error detection.

 Checking the code correctly according to grammar.


Uses/Application of Compilers

 Helps to make the code independent of the platform.

 Makes the code free of syntax and semantic errors.


 Generate executable files of code.

 Translates the code from one language to another.

You might also like