0% found this document useful (0 votes)
120 views18 pages

Programming Concepts - Ii: Ruchi Sharma

The document discusses key programming concepts like variables, constants, data types, expressions, input/output statements, conditional statements, and looping constructs. It explains that a programming language has these basic components and provides examples in C language. The user provides the program which is stored in memory by the computer. The computer also stores input, output and results. Conditional statements allow changing the execution flow based on conditions. Looping constructs are used to repeat tasks a specified number of times.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
120 views18 pages

Programming Concepts - Ii: Ruchi Sharma

The document discusses key programming concepts like variables, constants, data types, expressions, input/output statements, conditional statements, and looping constructs. It explains that a programming language has these basic components and provides examples in C language. The user provides the program which is stored in memory by the computer. The computer also stores input, output and results. Conditional statements allow changing the execution flow based on conditions. Looping constructs are used to repeat tasks a specified number of times.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

PROGRAMMING CONCEPTS - II

Ruchi Sharma
[email protected]

Ruchi Sharma [email protected] http://www.wiziq.com/tutor-profile/376074-Ruchi


Contents

 Quick Recall – Programming Concepts

 Components of a programming language

 Variables

 Constants

 Data types & Expressions

 Input & Output (I/O) Statements

 Conditional statements

 Looping constructs

Ruchi Sharma [email protected] http://www.wiziq.com/tutor-profile/376074-Ruchi


Quick Recall - Programming Concepts

 Computer languages can be classified in two broad

categories - Low level languages(machine friendly)

and High level languages(user friendly)

 We usually use HLL for programming to solve a given

problem.

 While programming, we can use either of the two

approaches – procedural or object oriented.

 A translator program called Complier converts the

HLL program to a LLL program understandable by

the computer.
Ruchi Sharma [email protected] http://www.wiziq.com/tutor-profile/376074-Ruchi
Computer & User -Who does what ?

User Computer
1. The user gives(keys in) the
program to the computer.
2. The computer stores it in
memory.
3. At the time of
execution(running the
program), the user inputs
the data.
4. The computer stores this
data too in the memory.

5. The computer processes the


data using the program.

Ruchi Sharma [email protected] http://www.wiziq.com/tutor-profile/376074-Ruchi


Computer & User -Who does what ? (Contd.)

User Computer

6. The computer stores the


output in the memory.*

7. The computer outputs the


data to the user.
8. The user gets the output.

* Note : During processing, the computer also stores the

intermediate results, if any, in the memory.

Ruchi Sharma [email protected] http://www.wiziq.com/tutor-profile/376074-Ruchi


Components of a Programming Language

A programming language has the following components

 Variables

 Constants

 Data types

 Expressions

 Input & Output statements

 Conditional Statements

 Looping Constructs

Ruchi Sharma [email protected] http://www.wiziq.com/tutor-profile/376074-Ruchi


Variables
Variables

 The computer stores program & data in memory.

 The computer memory can be visualised as a space

divided into several parts, each part called a location &

having a unique address.

Cell 1

Cell 2

Cell n

Ruchi Sharma [email protected] http://www.wiziq.com/tutor-profile/376074-Ruchi


Variables (Contd.)

 The information is stored in the memory in these cells.

A variable can be understood as “a location name”.

Examples

1. The statement

x = 10

will store the value 10 in a memory location(depicted by

a cell in the figure) named x.

2. The statement

s = ‘ruchi’

will store the string “ruchi” in the variable s.

Ruchi Sharma [email protected] http://www.wiziq.com/tutor-profile/376074-Ruchi


Variables - Facts

A variable is allocated memory randomly.

 Each variable holds an information of a particular type.

 Variables are used in a program to refer to the location(s)

where data needed by the program is/are stored.

 The value of a variable can be changed i.e. varied(hence the

name “VARIable”)

 Each time the value of a variable is written into memory,

the older one is washed out and the new one is retained.

Ruchi Sharma [email protected] http://www.wiziq.com/tutor-profile/376074-Ruchi


Constants

A constant is a value that remains unchanged.

 A constant can be a numeric constant or a character/string

constant. The examples used previously contain the constants

10 (numeric constant) & “ruchi”(string constant) respectively.

 A constant value can be assigned to a variable whereas the

reverse is not valid. E.g. –

x = 10 is acceptable whereas

10 = x is not !

Ruchi Sharma [email protected] http://www.wiziq.com/tutor-profile/376074-Ruchi


Data Types

A data type is something which determines the type of data

that a variable can hold.

 There are three basic types of data that are commonly used

integer, real & string.

 Related data of same type can be stored in adjacent locations

& is called an array. The elements of an array are denoted by

the same name but different subscripts.

E g - the roll numbers of the students of a class of 5 can be

stored in an array named ROLL & the roll numbers can be

referred to as

ROLL[1], ROLL[2], ROLL[3], ROLL[4], ROLL[5].


Ruchi Sharma [email protected] http://www.wiziq.com/tutor-profile/376074-Ruchi
Data Types (Contd.)

These roll numbers can be assigned values as :

ROLL[1] = 961001

ROLL[2] = 961002

ROLL[3] = 961003

ROLL[4] = 961004

ROLL[5] = 961005

These will be stored in memory in contiguous locations as :

961001 961002 961003 961004 961005

Ruchi Sharma [email protected] http://www.wiziq.com/tutor-profile/376074-Ruchi


Expressions

An expression is a combination of some operators and

operands.

e.g. – In mathematics,

7 x (4 + 19 ) – 34 / 5 is an expression.

(a – b) + c / 60 is an expression.

 In computer languages also, the expressions are similar to

those in mathematics, just that some symbols are different like,

we use * for a sign of multiplication.

 Every language specifies an order in which the operators are

evaluated in an expression.

Ruchi Sharma [email protected] http://www.wiziq.com/tutor-profile/376074-Ruchi


Input and Output Statements

Input

An input statement is used to take the input(s) from the user.

 The value(s) inputted by the user is/are stored in the designated

variable(s) in memory.

e.g. – an input statement in the language C is as under

scanf(“%d”, &x);

after execution of the above statement,

 the computer prompts the user to enter a value.

 the value entered by the user is stored in the variable x in

memory.

Ruchi Sharma [email protected] http://www.wiziq.com/tutor-profile/376074-Ruchi


Input and Output Statements (Contd.)

Output

An output statement is used to display

 an output to the user.

 a message to the user.

e.g. – an output statement in the language C is as under

1. printf(“%d”, x);

after execution of the above statement, the value of the variable

x is displayed for the user.

2. printf(“Hello Boss !”);

after execution of the above statement, the message Hello Boss !

is displayed for the user.


Ruchi Sharma [email protected] http://www.wiziq.com/tutor-profile/376074-Ruchi
Conditional Statements

In a programming language, there are statements which check for


a condition and accordingly the execution flow can be changed.
The most common conditional construct is of the format

IF (condition)
THEN
----------------------
ELSE
--------------------
Here, if the condition* evaluates to be “true”, THEN part is
executed (& ELSE part is skipped) & if it evaluates to “false”, ELSE
part is executed ( & IF part is skipped).
*NOTE - the condition should be a valid expression that can be
evaluated to either true or false.

Ruchi Sharma [email protected] http://www.wiziq.com/tutor-profile/376074-Ruchi


Looping Constructs

 Looping constructs are used when we need to repeat a task a

number of times or till some condition is met.

 A looping construct should have

 an initial condition – which starts the loop

 an increment – which advances the loop

 a termination condition – which helps come out of the loop

 The loops used in C language are :

1. do - while

2. while

3. for

Ruchi Sharma [email protected] http://www.wiziq.com/tutor-profile/376074-Ruchi


Ruchi Sharma [email protected] http://www.wiziq.com/tutor-profile/376074-Ruchi

You might also like