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

Introduction To Computers and Programming (CSE 101) : Dr. Ruhul Amin., Asst. Prof., CSE, NIT Jamshedpur

The document provides an introduction to computers and programming, emphasizing the importance of problem-solving and algorithm development. It outlines the steps involved in programming, including problem analysis, design, coding, and testing, and distinguishes between algorithms, flowcharts, and programming languages. Additionally, it discusses structured programming principles and the C programming language's structured nature.

Uploaded by

Vishal Maurya
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 views46 pages

Introduction To Computers and Programming (CSE 101) : Dr. Ruhul Amin., Asst. Prof., CSE, NIT Jamshedpur

The document provides an introduction to computers and programming, emphasizing the importance of problem-solving and algorithm development. It outlines the steps involved in programming, including problem analysis, design, coding, and testing, and distinguishes between algorithms, flowcharts, and programming languages. Additionally, it discusses structured programming principles and the C programming language's structured nature.

Uploaded by

Vishal Maurya
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/ 46

Introduction to Computers and

Programming (CSE 101)

Dr. Ruhul Amin.,


Asst. prof., CSE, NIT
Jamshedpur

ICP-PART-2
Problem solving -Introduction

● A computer is a very powerful and versatile machine


capable of performing a multitude of different tasks, yet
it has no intelligence or thinking power.
● The intelligence Quotient (I.Q) of a computer is zero.
● A computer performs many tasks exactly in the same
manner as it is told to do.
● A wrong or ambiguous instruction may sometimes
prove disastrous.
● In order to instruct a computer correctly, the user must
have clear understanding of the problem to be solved
Problem Solving Aspect
● Problem solving is a creative process
● A problem can be solved successfully only after making an
effort to understand the problem.
● To understand the problem, the following questions help:
– What do we know about the problem?
– What is the information that we have to process in order
the find the solution?
– What does the solution look like?
– What sort of special cases exist?
● The important aspect to be considered in problem-solving
is the ability to view a problem from a variety of angles.
Contd.
● There is no universal method for solving a given problem.
● A computer cannot solve a problem on its own.
● It is the programmer who has to write down the solution to
the problem in terms of simple operations which the
computer can understand and execute
● It is important for all of us
– To understand how to use computers effectively to solve our
problems
– not as the users of the computers,
– we will be able to tell the computer that how to solve our problem.
Contd..

● Computer can be solved:


– If we know what are the steps that we must execute/perform in
order to arrive desired output
● Program Development Steps
– Defining or Analyzing the problem
– Design (Algorithm)
– Coding
– Documenting the program
– Compiling and Running the Program
– Testing and Debugging
– Maintenance
Analyzing or Defining the Problem

● The problem is defined by doing a preliminary


investigation
● Defining a problem helps us to understand the problem
clear.
● It is also known as Program Analysis
● Tasks in defining a problem:
– Specifying the input requirements
– Specifying the output requirements
– Specifying the processing requirements
Design
● A design is the path from the problem to a solution
in code
● A well designed program is more likely to be:
– Easier to read and understand later
– Less of bugs and errors
– Easier to extend to add new features
● Use Top-Down programming design
– It is a structured design technique which breaks up the
problem into a set of sub-problems called Modules and
creates a hierarchical structure of modules.
Contd.

● Top-down design has the following advantages:


– Breaking up the problem into parts helps us to clarify
what is to be done
– At each step of refinement, the new parts become
more focussed and, therefore, easier to design
– Modules may be reused
– Breaking the problem into parts allows more than
one person to work on the solution simultaneously
Algorithm

● An algorithm is sequence of steps to solve problems


– Written in natural language such as English
– written precisely enough so as to be unambiguously
understood by humans.
● An algorithm as a solution to the problem
● Whereas the program is the translation of the solution
from English to a programming language that a
computer can understand
Contd..

● An algorithm can be defined as “a complete, unambiguous, finite


number of logical steps for solving a specific problem”.

Step1. Identification of input


Step2: Identification of output
Step3 : Identification the processing operations
Step4 : Processing Definiteness
Step5 : Processing Finiteness
Step6 : Possessing Effectiveness
An algorithm must possess the
following properties
● Finiteness: The algorithm must always terminate after a
finite number of steps
● Definiteness: Each step must be precisely defined; the
actions to be carried out must be rigorously and
unambiguously specified for each case.
● Effectiveness: All operations to be performed must be
sufficiently basic that they can be done exactly and in finite
length.
● Input: An algorithm has zero or more inputs, taken from a
specified set of objects
● Output : An algorithm has one or more outputs, which have
a specified relation to the inputs
Problems Algorithms Programs

● For each problem or class of problems, there may be many


different algorithms.
● For each algorithm, there may be many different implementations
(programs).
An algorithm may be expressed in a number of
ways

● Natural language(Algorithm): usually verbose and


ambiguous
● Flow charts: avoid most (if not all) issues of ambiguity;
difficult to modify w/o specialized tools; largely
standardized
● Pseudo-code: also avoids most issues of ambiguity;
vaguely resembles common elements of programming
languages; no particular agreement on syntax.
Algorithm for Telephonic Conversation
(Using Landline)

1. Lift the handset


2. Check for Dial tone
3. If dead tone
– Lodge a complaint
– STOP
4. Dial the number
5. If engaged tone then
– Close connection
– GOTO Step 1
Else
Algorithm to find the average of three numbers

Step 1 Read the numbers a, b, c


Step 2 Compute the sum of a, b and c
Step 3 Divide the sum by 3
Step 4 Store the result in variable d
Step 5 Print the value of d
Step 6 End of the program
Algorithm for
Simple interest = P*N* R/100.

Step 1: Read the three input quantities’ P, N and R.


Step 2 : Calculate simple interest as
Simple interest = P* N* R/100
Step 3: Print simple interest.
Step 4: Stop.
Algorithm for factorial of number(N!)

Step 1: Start
Step 2: Initialize factorial to be 1, i to be 1
Step 3: Input a number n
Step 4: Check whether the number is 0. If so report factorial
is 1 and goto step 9
Step 5: Repeat step 6 through step 7 n times
Step 6: Calculate factorial = factorial * i
Step 7: Increment i by 1
Step 8: Report the calculated factorial value
Step 9: Stop
To find the sum of N natural numbers
Step 1: Start
Step 2: Declare i,n & sum of integer type.
Step 3: Set sum to zero.
Step 4: Read value of n.
Step 5: Set i to 1.
Step 6: Add current value of i to sum.
Step 7: Repeat step 6 until i reaches to n.
Step 8: Print sum.
Step 9: End.
to find the sum of even & odd numbers.
Step 1: Start
Step 2: Declare n,i,evensum & addsum of integer type.
Step 3: Set evensum & oddsum to zero.
Step 4: Read value of n.
Step 5: Set i to 1.
Step 6: Check whether the number is divisable by 2 or not.
If yes add current value of i to evensum otherwise add to
oddsum.
Step 8: Repeat step 6 until i reatches to n.
Step 9: Print evensum & oddsum.
Step 10: End.
Measuring Performance

● How can we talk precisely about the "cost" of


running an algorithm?
● What does "cost" mean? Time? Space? Both?
Something else?
● This is primarily a topic for a course in
algorithms, like CS 201.
Flowchart

● A flow chart is a step by step diagrammatic representation


of the logic paths to solve a given problem.
Or
● A flowchart is visual or graphical representation of an
algorithm.
● This methods to b used to solve a given problem and help
a great deal to analyze the problem and plan its solution in
a systematic and orderly manner
● A flowchart when translated in to a proper computer
language, results in a complete program.
Advantages of Flowcharts

1. The flowchart shows the logic of a problem displayed in


pictorial fashion which felicitates easier checking of an
algorithm.
2. The Flowchart is good means of communication to other
users. It is also a compact means of recording an
algorithm solution to a problem.
3. The flowchart allows the problem solver to break the
problem into parts. These parts can be connected to
make master chart.
4. The flowchart is a permanent record of the solution
which can be consulted at a later time.
Differences between Algorithm and
Flowchart
Algorithm Flowchart

A method of representing the Flowchart is diagrammatic representation


step-by-step logical procedure for of an algorithm. It is constructed using
solving a problem different types of boxes and symbols.

It contains step-by-step English The flowchart employs a series of blocks


descriptions, each step representing a and arrows, each of which represents a
particular operation leading to solution of particular step in an algorithm
problem

These are particularly useful for small These are useful for detailed
problems representations of complicated programs

For complex programs, algorithms prove For complex programs, Flowcharts prove
to be Inadequate to be adequate
Symbols used in Flow-Charts
Contd..
Flowchart to illustrate how to make a
Land phone telephone call
Flowchart to find the factorial of given
positive integer N.
Adding the integers from 1 to 100 and
to print the sum.
Pseudo code

● It is more formal representation than the algorithm.


● Very close to the actual programming language representation.
● In this each of the steps will be written via operators statements
equivalent to some programming language instructions.
● All pseudo codes will start with keyword “START” and complete
with keyword “STOP”
1. START 7. end for
2. read n 8. average=sum/n
3. sum=0 9. print average
4. for i=1 to n do 10. STOP
5. read numberi
6. sum=sum+numberi
What is programming language?

● A programming language is a notation designed to connect


instructions to a machine or a computer.
● Programming languages are mainly used to control the
performance of a machine or to express algorithms.
● At present, thousand programming languages have been
implemented.
● The program can be divided into two forms such as syntax and
semantics.
Machine Language

● Expressed in binary.
– 10110100 may mean ADD, 01100101 may mean SUB, etc.
● Directly understood by the computer.
● Not portable; varies from one machine type to another.
– Program written for one type of machine will not run
on another type of machine.
● – Difficult to use in writing programs.
Assembly Language

● Mnemonic form of machine language.


● Easier to use as compared to machine language.
– • For example, use “ADD” instead of “10110100”.
● Not portable (like machine language).
● Requires a translator program called .
Contd..

● Assembly language is also difficult to use


in writing programs.
● Requires many instructions to solve a problem.
● Example: Find the average of three numbers.
High-Level Language

● Machine language and assembly language are called low-level


languages.
– They are closer to the machine.
– Difficult to use.
● High-level languages are easier to use.
– They are closer to the programmer.
– Examples:
● Fortran, C, C++, Java.
● Requires an elaborate process of translation.
– Using a software called .
● They are portable across platforms.
Types of languages

● Machine languages — interpreted directly in hardware


● Assembly languages — thin wrappers over a
corresponding machine language
● High-level languages — anything machine-independent
● System languages — designed for writing low-level
tasks, like memory and process management
● Scripting languages — generally extremely high-level
and powerful
Compilers

● Programs determine the high level programming languages cannot


be directly understood by the machine.
● We need some tools using which we actually run this program.
● Compilers Developed
● A complier essentially translates, a program in a high level
language such as C to an equivalent machine language program for
a particular kind of a CPU.
Structured Programming

● Structured programming (sometimes known as


)
● It refers to a programming strategy that encompasses a number of
methodologies to produce good quality design and code
– It impact on easily understood, tested, debugged, modified and
maintained in future.
● Three principles of structured programming
– Program design using Top-down or bottom-up programming

– Decomposition of program into components i.e modular


programming
– Structuring of control flow
Top-Down Design

● A program is divided into a main module and its related modules.


Each module is in turn divided into submodules until the resulting
modules are understood without further division.
● During this approach the design is used Divide and conquer.
● The problem is divided in smaller sub problems. These
sub-problems are further divided into even small sub problems.
Bottom up design

● This is reverse of top-down approach.


● Initially identification of smallest sub problem of the total problem,
which can easily implemented.
● Drawback:
– Rarely possible to identify smallest sub components needed
for program.
Modular Programming

● To design a program various components(Modules)to be used.


● A module is a portion of the program which is responsible for to
carry out a certain task and can be used with other modules.
Why C is Structured programming?

● Structured programming is a programming paradigm


which follows a particular structure for writing the
instruction.
● c is a structured language because there is restriction
where you can declare variables, place header files and
use functions (for example you cannot declare a
variable after a function call)..
Basic structure of C Program
The C Compilation Model
The C Compilation Model

Program edited in
Phase 1 Editor Editor and stored
Disk
on disk

Preprocessor
Phase 2 Preprocessor
Disk program processe
the code

Creates object code


Phase 3 Compiler Disk and stores on disk
Contd..

Links object code


Phase 4 Linker Disk with libraries and
stores on disk
Primary memory

Phase 5 Loader
Puts program in
memory
Sample programs

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy