Sie sind auf Seite 1von 45

UNIT –I

Basics of Programming
Introduction to Computer
• What is Computer?
– Electronic Machine that takes input, Process it and
generate desired output quickly
Use of Computer
Components of Computer
Computer Programming Basics
• Computer programs are a detailed set of
instructions given to the computer.

• They tell the computer:


1. What actions you want the computer to perform
2. The order those actions should happen in
• We Want the computer to perform the
expected task automatically
Problem Solving
• What to have for dinner tonight?
• Which route to take to work?
• How to fix a project that’s running behind
schedule?
• How to change from an uninspiring job to a
career you’re really passionate about?
Problem Solving
• Understanding the Problem
• Devising a Plan
• Carrying out the Plan
• Looking Back –
– you can improve
your problem-solving
and tackle any issue
systematically.
Understanding the Problem

• If the problem is “always late to work”…


• Why am I late to work?
I always click the snooze button and just want to go on sleeping.
• Why do I want to go on sleeping?
• I feel so tired in the morning.
• Why do I feel tired in the morning?
• I slept late the night before, that’s why.
• Why did I sleep late?
• I wasn’t sleepy after drinking coffee, and I just kept scrolling my
Facebook feed and somehow I couldn’t stop.
• Why did I drink coffee?
• Because I was too sleepy at work in the afternoon, not having
enough sleep the night before.
How Computer Performs Tasks??
• Need to Write a Program/Software to perform
task.
• An effective program therefore needs:
1. A thorough understanding of the problem
2. A well thought-out, step-by-step solution to the
problem
Task: Going to School
Task: Preparing Tea
•Put a pot on the gas

•Pour a cup of milk


•Add sugar
•Add tea
•Let it boil for 5 mins
•Pour tea in cup
•Enjoy it

So Step by step Solution to perform a Task is Nothing but an Algorithm


ALGORITHMS

• A typical programming task can be divided into two


phases:
• Problem solving phase
– produce an ordered sequence of steps that describe
solution of problem
– this sequence of steps is called an algorithm
• Implementation phase
– implement the program in some programming language
Algorithm
• An algorithm is Finite set of sequence of Steps
to perform specific Task.
• Characteristics of algorithm
– Finiteness: finite number of steps
– Definiteness:
• Simple
• Each step Precisely defined
• unambiguous
Characteristics of algorithm

• Generality
– Should solve all problems of a particular type
• Effectiveness
– Should take less time
• Input & output
– Must precise inputs and generate imtermediate as
well as final output
Algorithm to find addition of two
numbers
• Step 1: START
• Step 2: Read Values of A & B
• Step 3:Compute
Sum=A+B
• Step 4: Display Sum
• Step 5: Stop
Algorithm to find area of circle
• Step 1: START
• Step 2: Define constant Π=3.142
• Step 3: Read radius of circle r
• Step 4:Compute
Area= Π *r*r
• Step 5: Display Area
• Step 6: Stop
Algorithm to find maximum number
between two
• Step 1: START
• Step 2: Read Values of A & B
• Step 3: if (A>B)
Display A
else
Display B
• Step 4: STOP
Algorithm to swap two numbers
• Step 1: START
• Step 2: Read Values of A & B A B
• Step 3: temp=A
• Step 4: A=B
A B Temp
• Step 5: B=temp 10 20

• Step 6: STOP 10
20
20
20
10
10
20 10 10
Algorithm Logic
• Sequential Flow
• Conditional Flow
• Repetitive Flow
Sequential Flow

• All Steps are executed in given sequence


– E.g. addition of two numbers
• Step 1: START
• Step 2: Define constant
Π=3.142
• Step 3: Read radius of
circle r
• Step 4:Compute
Area= Π *r*r
• Step 5: Display Area
• Step 6: Stop
Conditional Flow
• Decision to be made based on Condition
– E.g Find max number between two
• Step 1: START
• Step 2: Read Values of A &
B
• Step 3: if (A>B)
Display A
else
Display B
• Step 4: STOP
Repetitive Flow
• Algorithm to find Sum of number from 1 to N
• Step 1:START
• Step 2: Read value of N
• Step 3: Initialize Sum=0, i=1
• Step 4: compute
Sum=Sum+i
• Step 5: i=i+1
• Step 6: If (i<=N) go to Step 4
• Step7: Display Sum
• Step 8: Stop
Psudocode
• informal language that helps programmers
develop algorithms
• Pseudocode is a step-by-step verbal outline of
your code
• Pseudocode serves as
– an informal guide,
– a tool for thinking through program problems,
– a communication device that can help you explain
your ideas to other people.
Psudocode
• If student's grade is greater than or equal to
60
• Print "passed" Algorithmic step
• if (A>B)
• else Print "passed"

• Print "failed" else


Print "failed"
The Flowchart
• A graphical representation of the sequence of
operations to perform Specific Task.
• A flowchart is a type of diagram that
represents an algorithm, workflow or process
The Flowchart
A Flowchart
– shows logic of an algorithm
– emphasizes individual steps and their
interconnections
– e.g. control flow from one action to the next
Flowchart Symbols
Basic
Flowchart Symbols
• On page Connector

• Off page connector


Flowchart to find addition of two numbers
Flowchart to find area of circle
Using Decision symbol
Find maximum number between two
Flowchart to find result of the student
Test your understanding
• Psudocode
• Enter a number from keyboard
• If value greater than 10
• Say number greater than 10
• If value less than 10
• Say number less than 10
Memory Concepts
RAM Vs SAM
•Sequential Access
•Slow
•Cheap
•Non Volatile

•Random Access
•Fast
•Costly than Sam
•Volatile
C programming Environment
Editor
• An editor used to write a c program
• E.g. notepad, notepad++, gedit
• C programs are written in human readable
source code that is not directly executable by
a computer
Preprocessor
• C Preprocessor is just a text substitution tool
and it instructs the compiler to do required
pre-processing before the actual compilation.
• # include<stdio.h>
– Includes standard input output file in your code
Compiler
• Machine Language
– Language of 0’s and 1’s understood by computer
– Lowest level directly executed by hardware

C Program Object Code


Hello.c Compiler Hello.obj

Translates
Linking
• The object code is combined with required
supporting code to make an executable
program
Loading
• Loader loads executable code into main
memory

Main
.exe CPU
Memory

Executable file
Execution
• Executes or Run the C Program
C programming Environment
Test Ur understanding
• The brain of any computer system is
a. ALU
b. Memory
c. CPU
d. Control Unit
• (c)

Das könnte Ihnen auch gefallen