0% found this document useful (0 votes)
26 views43 pages

1 Introduction To C 21dec2020

The document provides information about algorithms, how to write algorithms, flowcharts, and some examples of practice problems involving algorithms. It discusses that an algorithm is a sequence of steps to solve a problem, and outlines the typical steps to write an algorithm: define the input, variables, operations, and output. It also explains what a flowchart is and how it can be used to design a solution to a problem visually using standard symbols. The document then provides some practice problems asking the reader to write IF conditions and compare numbers.

Uploaded by

Nand Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views43 pages

1 Introduction To C 21dec2020

The document provides information about algorithms, how to write algorithms, flowcharts, and some examples of practice problems involving algorithms. It discusses that an algorithm is a sequence of steps to solve a problem, and outlines the typical steps to write an algorithm: define the input, variables, operations, and output. It also explains what a flowchart is and how it can be used to design a solution to a problem visually using standard symbols. The document then provides some practice problems asking the reader to write IF conditions and compare numbers.

Uploaded by

Nand Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

Introduction

1
Algorithm
An algorithm is a sequence of steps to
solve a particular problem.
or
algorithm is an ordered set of
unambiguous steps that produces a
result and terminates in a finite time.

2
3
HOW TO WRITE ALGORITHMS
Step 1 Define your algorithms input

Step 2 Define the variables

Step 3 Outline the algorithm's operations

Step 4 Output the results of your algorithm’s


operations

4
FlowChart
• Flowchart uses different symbols to design a solution to
a problem.

• It is another commonly used programming tool.

• By looking at a Flowchart, one can understand the


operations and sequence of operations performed in a
system.

• Flowchart is often considered as a blueprint of a design


used for solving a specific problem

5
• Flowchart is diagrammatic /Graphical representation of
sequence of steps to solve a problem. To draw a
flowchart following standard symbols are use:

6
7
8
9
10
11
12
13
14
15
16
17
18
No Ye
If Print A is
If A <B s
A==B smaller
Ye
s
No

Print both
number are Print B is
same smaller

19
20
21
22
Practice
• Write if conditions for these situations.
• Let’s say we are dealing with an integer called n.
– The number is between 5 and 25 inclusive.
– Less than 12 or equal to 95.
– Even and less than 100.
– Between 10 and 20, or between 80 and 90.
– Ends in 7.
– Is neither 13 nor 17.
• Compare two numbers x and y.
– y is positive, and x is strictly between 0 and y.
Practice
Q1. Write a C program to input basic salary of an employee and calculate its Gross salary
according to following:
Basic Salary <= 10000 : HRA = 20%, DA = 80%
Basic Salary <= 20000 : HRA = 25%, DA = 90%
Basic Salary > 20000 : HRA = 30%, DA = 95%

Q2.Write a C program to input electricity unit charges and calculate total electricity bill
according to the given condition:
For first 50 units Rs. 0.50/unit
For next 100 units Rs. 0.75/unit
For next 100 units Rs. 1.20/unit
For unit above 250 Rs. 1.50/unit
An additional surcharge of 20% is added to the bill

Q3. Write a C program to input month number and print number of days in that month.

Q.4. Write a C program to check whether a number is divisible by 5 and 11 or not.

24
von neumann architecture

25
26
27
Constants, Variables and Keywords

28
Constants

29
• Rules for Constructing Integer Constants
– An integer constant must have at least one digit.
– It must not have a decimal point.
– It can be either positive or negative.
– If no sign precedes an integer constant it is assumed to be
positive.
– No commas or blanks are allowed within an integer constant.
– The allowable range for integer constants is -32768 to 32767.

30
31
keywords

32
Basics
• Each instruction in a C program is written as a separate
statement. Therefore a complete C program would
comprise of a series of statements.
• The statements in a program must appear in the same
order in which we wish them to be executed; unless of
course the logic of the problem demands a deliberate
‘jump’ or transfer of control to a statement, which is out
of sequence.
• Blank spaces may be inserted between two words to
improve the readability of the statement. However, no
blank spaces are allowed within a variable, constant or
keyword.

33
• All statements are entered in small case letters.

• C has no specific rules for the position at which a


statement is to be written. That’s why it is often called a
free-form language.

• Every C statement must end with a ;. Thus ; acts as a


statement terminator.

34
Example:

35
Receive input

36
37
C Instructions

•Type Declaration

•Arithmetic instruction

•Control instruction

38
Type Declaration

int bas;
float rs, grosssal ;
char name, code ;

39
40
41
42
43

You might also like