0% found this document useful (0 votes)
94 views34 pages

FOP Unit-1 Part-1 (Introduction To Computer Programming)

This document provides an introduction to computer programming, including: 1) An overview of computer systems, hardware, software, and the input-processing-output model. 2) A discussion of programming paradigms, including imperative and declarative paradigms. Imperative paradigms include procedural, object-oriented, and parallel processing approaches. 3) An outline of topics to be covered in the unit, such as programming paradigms, algorithms, flowcharts, and programming constructs.

Uploaded by

Viral Panchal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
94 views34 pages

FOP Unit-1 Part-1 (Introduction To Computer Programming)

This document provides an introduction to computer programming, including: 1) An overview of computer systems, hardware, software, and the input-processing-output model. 2) A discussion of programming paradigms, including imperative and declarative paradigms. Imperative paradigms include procedural, object-oriented, and parallel processing approaches. 3) An outline of topics to be covered in the unit, such as programming paradigms, algorithms, flowcharts, and programming constructs.

Uploaded by

Viral Panchal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 34

Fundamentals of Programming (CE3002) Unit – 1: Introduction of Computer Programming

Chhotubhai Gopalbhai Patel Institute of


Technology, Bardoli

Subject
Fundamentals of Programming (CE3002)

Unit – 1
Introduction of Computer Programming
(Part – 1)

Prepared by – Mr. Viral H. Panchal 1


Fundamentals of Programming (CE3002) Unit – 1: Introduction of Computer Programming

CONTENTS
1. Understanding Computer Systems and Computer Languages
2. Programming Paradigm and Classification
2.1. Types of Programming Paradigms
2.1.1. Imperative Programming Paradigms
2.1.2. Declarative Programming paradigms
3. Programming Development Process
4. Pseudocode Statements and Flowchart
4.1. Algorithm
4.2. Flowchart
4.3. Programming Constructs / Programming Structures
4.4. Algorithm and Flowchart Examples

Prepared by – Mr. Viral H. Panchal 2


Fundamentals of Programming (CE3002) Unit – 1: Introduction of Computer Programming

1. Understanding Computer Systems and Computer Languages


A computer system is a combination of all the components required to process
and store data using computer. Every computer system is composed of multiple
pieces of hardware and software.

Hardware is the equipment, or the physical devices, associated with a computer.


For example, keyboards, mice, speakers, and printers are all hardware.

Software is computer instructions that tell the hardware what to do. Software is
programs - instructions written by programmers.

Software can be classified as application software or system software.

• Application software comprises all the programs you apply to a task -


word-processing programs, spreadsheets, payroll and inventory programs,
and even games.
• System software comprises the programs that you use to manage your
computer, including operating systems such as Windows, Linux, or UNIX.

Together, computer hardware and software accomplish three major operations


in most programs: input, processing, and output.

Input – Data items enter the computer system and are put into memory, where
they can be processed. Hardware devices that perform input operations include
keyboards and mice. Data items include all the text, numbers, and other
information that are processed by a computer.

Processing – Processing data items may involve organizing or sorting them,


checking them for accuracy, or performing calculations with them. The hardware
component that performs these types of tasks is the central processing unit, or
CPU.

Output – After data items have been processed, the resulting information
usually is sent to a printer, monitor, or some other output device so people can view,
interpret, and use the results.

Prepared by – Mr. Viral H. Panchal 3


Fundamentals of Programming (CE3002) Unit – 1: Introduction of Computer Programming

Some people consider storage as a fourth major computer operation. Instead of


sending output to a device such as a printer, monitor, or speaker where a person
can interpret it, you sometimes store output on storage devices, such as a disk or
flash media. People cannot read data directly from these storage devices, but the
devices hold information for later retrieval. When you send output to a storage
device, sometimes it is used later as input for another program.

You write computer instructions in a computer programming language, such as


Visual Basic, C#, C++, or Java. Just as some people speak English and others
speak Japanese, programmers also write programs in different languages.

[The instructions you write using a programming language are called program code;
when you write instructions, you are coding the program.]

When you write a program, you usually type its instructions using a keyboard.
When you type program instructions, they are stored in computer memory, which is
a computer’s temporary, internal storage. Internal storage is volatile - its contents
are lost when the computer is turned off or loses power. Usually, you want to be
able to retrieve and perhaps modify the stored instructions later, so you also store
them on a permanent storage device, such as a disk. Permanent storage devices
are non-volatile - that is, their contents are persistent and are retained even when
power is lost.

[Random access memory, or RAM, is a form of internal, volatile memory. It is


hardware on which the programs that are currently running and the data items that are
currently being used are stored for quick access.]

After a computer program is stored in memory, it must be translated from your


programming language statements to machine language that represents the millions
of on/off circuits within the computer. Each programming language uses a piece of
software, called a compiler or an interpreter, to translate your program code into
machine language. Machine language is also called binary language, and is
represented as a series of 0s and 1s.

Prepared by – Mr. Viral H. Panchal 4


Fundamentals of Programming (CE3002) Unit – 1: Introduction of Computer Programming

[The program statements you write in a programming language are known as source
code. The translated machine language statements are known as object code.]

Only after program instructions are successfully translated to machine code the
computer can carry out the program instructions. When instructions are carried out,
a program runs, or executes. In a typical program, some input will be accepted,
some processing will occur, and results will be output.

2. Programming Paradigm and Classification


The programming paradigm is defined as a set of principles, ideas, design
concepts and norms that defines the manner in which the program code is written
and organized.

The programming paradigm does not specify the programming language


syntax. The paradigm simply defines the program structure and the set of principles
that the programming language compiler should enforce.

A programming paradigm is a framework that defines how the programmer can


conceptualize and model complex problem to be solved.

2.1. Types of Programming Paradigms

Figure 2.1.1: Types of programming paradigm

Prepared by – Mr. Viral H. Panchal 5


Fundamentals of Programming (CE3002) Unit – 1: Introduction of Computer Programming

The programming paradigms can be classified into two main types. The
paradigm type depends upon the programming language features and a
particular style of organizing the program code.

1. Imperative Programming Paradigm


2. Declarative Programming Paradigm

2.1.1 Imperative Programming Paradigms


The imperative paradigm is said to be command driven. The program code
in imperative paradigm programming language directs the program execution
as sequence of statements executed one by one.

The imperative style program consists of set of program statements. Each


statement directs the computer to perform specific task.

In imperative style program, the programmer has to elaborate each


statement in details. Each statement directs what is to be done and how it is to
be done.

The execution of the program statements is decided by the control flow


statements. And the program flow can be directed as per the program logic.

The imperative paradigm programming languages include C, Fortran, Algol,


Pascal and Basic.

Imperative programming is divided into three broad categories: Procedural,


OOP and parallel processing. These paradigms are as follows:

Procedural programming paradigm -

The program based on procedural paradigm consist of set of procedures.


The procedures are also referred as function, method or subroutines. The
program structure in procedural programming consists of set of functions. Each
performs a specific operation.

Prepared by – Mr. Viral H. Panchal 6


Fundamentals of Programming (CE3002) Unit – 1: Introduction of Computer Programming

The function consists of group of computational steps that directs the


computer to perform specific operation. The function once defined can be called
many times in the program to repeat the same operation.

The programmer can either use standard library functions or create library
of user defined functions.

The examples of procedural programming languages are C, C++, Java,


Pascal, etc.

Object-oriented programming -

In object-oriented programming, all the program components are


represented as objects. An object binds the data and associated methods
together as single unit. As such the programmer can control the data access
permissions by defining the access specifier.

The object-oriented programming protects the program data from


inadvertent operations by another methods. And therefore, the object-oriented
programming offers robust security features.

The examples of object-oriented programming languages are C++, Java,


Python, VB.Net, etc.

Parallel processing approach -

Parallel processing is the processing of program instructions by dividing them


among multiple processors. A parallel processing system have many numbers of
processor with the objective of running a program in less time by dividing them.

This approach seems to be like divide and conquer. Examples are NESL (one
of the oldest one) and C/C++ also supports because of some library function.

Prepared by – Mr. Viral H. Panchal 7


Fundamentals of Programming (CE3002) Unit – 1: Introduction of Computer Programming

2.1.2 Declarative Programming Paradigms


The declarative paradigm is a programming paradigm that is focused on the
logic of the program and the end result. In this paradigm the control flow is not
the important element of the program.

The main focus of the declarative style of programming is achieving the end
result. This paradigm is straight forward and to the point while writing the
program code.

The declarative approach to the programming is pretty much straight


forward that leads to what is to be done.

On the contrary, the imperative style of programming consists of number of


computational statements that focuses on how it is to be done.

Declarative programming is divided into three broad categories: Logic,


Functional and Database programming. These paradigms are as follows:

Logic programming paradigm -

The logic programming is a declarative programming paradigm that is


based on the logic and the control. The term logic essentially means facts and
rules, whereas the control means an order of rules.

The term algorithm is defined as logic plus control (logic + control). The logic
defines what should be solved whereas the control defines how it should be
solved.

The main advantage of the logic programming is that the programmer needs
to simply define the what part of the problem. And the system finds the best
solution to that problem.

The logic programming is an abstract model of computation. It is based on


the first order predicate logic. The predicate logic is also referred to as first
order logic.

Prepared by – Mr. Viral H. Panchal 8


Fundamentals of Programming (CE3002) Unit – 1: Introduction of Computer Programming

The clauses are an important element of the logic programming. In other


words, a logic program is a set of clauses.

The Prolog is an example of declarative paradigm rule-based logic


programming language. The Prolog program consist of set of program
statements expressed in terms of facts, rules and the control.

Functional programming paradigm -

The functional programming paradigms has its roots in mathematics and it is


language independent.

The key principle of this paradigms is the execution of series of mathematical


functions. The central model for the abstraction is the function which are meant
for some specific computation and not the data structure. Data are loosely
coupled to functions. The function hides their implementation.

Function can be replaced with their values without changing the meaning of
the program. Some of the languages like perl, javascript mostly uses this
paradigm.

Database/Data driven programming approach -

This programming methodology is based on data and its movement. Program


statements are defined by data rather than hard-coding a series of steps. A
database program is the heart of a business information system and provides
file creation, data entry, update, query and reporting functions.

There are several programming languages that are developed mostly for
database application. For example, SQL. It is applied to streams of structured
data, for filtering, transforming, aggregating (such as computing statistics), or
calling other programs. So, it has its own wide application.

Prepared by – Mr. Viral H. Panchal 9


Fundamentals of Programming (CE3002) Unit – 1: Introduction of Computer Programming

3. Programming Development Process


A programmer’s job involves writing instructions, but a professional programmer
usually does not just sit down at a computer keyboard and start typing.

Programming is a process of problem solving. To be a good problem solver and


a good programmer, you must follow good problem-solving techniques.

In Programming Development Process, the programming steps or problem-


solving process requires the following steps. This is also referred to as the
Programming Development Cycle.

1. Problem analysis - Understand the problem.


2. Logic formulation or plan the logic - Design the algorithm.
3. Code the program - Write the Source Program using a Programming
Language
4. Compile and link the source program to produce the executable program -
Use a compiler or interpreter to translate the program into machine
language (Machine Code or Object code).
5. Test the executable program - confirm your program’s correctness by testing
the executable program several times using a variety of data.
6. Use the executable program - Put the program into production.
7. Maintain the program - Make changes or revisions for new requirements in
the program's input/process/output.

Figure 3.1illustrates the program development cycle.

Prepared by – Mr. Viral H. Panchal 10


Fundamentals of Programming (CE3002) Unit – 1: Introduction of Computer Programming

Figure 3.1: Program development cycle

Problem analysis -

Analyzing the problem is the first and most crucial step in programming. This
step requires you to do the following:

• Completely understand the problem.


• Understand all the problem requirements with regards to its INPUT,
OUTPUT and PROCESS operations.
• If the problem is complex, divide the problem into sub-problems, analyze
each sub-problem, and understand each sub-problem’s requirements.

Logic formulation or plan the logic -

The heart of the programming process lies in planning the program’s logic.
During this phase, the programmer plans the steps of the program, deciding
what steps to include and how to order them. This is known as the algorithm.

You can plan the solution to a problem in many ways. The two most common
planning tools are flowcharts and pseudocode. If the problem is complex, you
broke the problem into subproblems, you need to design an algorithm for each

Prepared by – Mr. Viral H. Panchal 11


Fundamentals of Programming (CE3002) Unit – 1: Introduction of Computer Programming

subproblem. Once you design an algorithm, you need to check it for correctness.
You can sometimes test an algorithm’s correctness by using sample data. At
other times, you might need to perform some mathematical analysis to test the
algorithm’s correctness.

Planning the logic includes thinking carefully about all the possible data
values a program might encounter and how you want the program to handle
each scenario.

The process of walking through a program’s logic on paper before you


actually write the program is called desk-checking. The programmer shouldn’t
worry about the language syntax during this stage, but should rather focus on
figuring out what sequence of events will lead from the available input to the
desired output.

Code the program -

Once you have designed the algorithm and verified its correctness, the next
step is to convert it into an equivalent programming code by coding the
program in one of more than hundreds of programming languages.

You then use a text editor to enter the programming code or the program
into a computer.

Compile and link the source program to produce the executable program -

Next, you must make sure that the program follows the language’s syntax. To
verify the correctness of the syntax, you run the code through a compiler.

A computer program must be free of syntax errors before you can execute
it. Usually, the software displays a list of syntax errors, which the programmer
corrects. If the compiler generates error messages, you must identify the errors
in the code, correct them, and then run the code through the compiler again.

When all the syntax errors are removed, the compiler generates the
equivalent machine code, the linker links the machine code with the system’s

Prepared by – Mr. Viral H. Panchal 12


Fundamentals of Programming (CE3002) Unit – 1: Introduction of Computer Programming

resources, and the loader places the program into main memory so that it can
be executed.

Usually when writing a program, a programmer might need to re-compile


the code several times. An executable program is created only when the code is
free of syntax errors. When you run an executable program, it typically also
might require input data.

Figure 3.2 below shows a diagram of this entire process.

Figure 3.2: Creating an executable program

Test the executable program -

The final step is to execute the program and test with some data to verify for
correct outputs. The compiler guarantees only that the program follows the
language’s syntax. It does not guarantee that the program will run correctly. A
program that is free of syntax errors is not necessarily free of logical errors.

During execution, the program might terminate abnormally due to logical


errors, such as division by zero or may not even terminate due to an endless
loop. Even if the program terminates normally, it may still generate erroneous

Prepared by – Mr. Viral H. Panchal 13


Fundamentals of Programming (CE3002) Unit – 1: Introduction of Computer Programming

results. Under these circumstances, you may have to re-examine the code, the
algorithm, or even the problem analysis.

Use the executable program -

Once the program is tested adequately, it is ready for an individual or


organization to use it. Putting the program into production might mean simply
running the program only once, if it was written to satisfy a user’s request for a
special list. However, the process might take longer if the program will be run on
a regular basis, or if it is one of a large system of programs being developed.

Maintain the program -

After programs are put into production, making necessary changes is called
maintenance. These changes or revisions maybe for new requirements in the
Program's Input/Process/Output. Like new format or specification for input or
output data or requiring a new revision or additional operating process or
computation.

When you make changes to existing programs, you repeat the development
cycle. That is, you must understand these changes, plan, code, translate, and test
them again before putting them into production.

If a substantial number of program changes are required, the original


program might be retired, and the program development cycle started for a
new program.

Prepared by – Mr. Viral H. Panchal 14


Fundamentals of Programming (CE3002) Unit – 1: Introduction of Computer Programming

4. Pseudocode Statements and Flowchart


When programmers plan the logic for a solution to a programming problem,
they often use one of two tools: pseudocode (pronounced “sue-doe-code”) or
flowcharts.

Pseudocode is an English-like representation of the logical steps it takes to solve


a problem.

A flowchart is a pictorial representation of the same thing.

Pseudo is a prefix that means “false,” and to code a program means to put it in
a programming language; therefore, pseudocode simply means “false code,” or
sentences that appear to have been written in a computer programming language
but do not necessarily follow all the syntax rules of any specific language.

4.1. Algorithm
An algorithm is defined as sequence of steps to solve a problem (task). The
steps must be finite, well defined and unambiguous. Writing algorithm requires
some thinking. Algorithm can also be defined as a plan to solve a problem and
represents its logic. Note that an algorithm is of no use if it does not help us
arrive at the desired solution.

For accomplishing a particular task, different algorithms can be written.


Different algorithms can differ in their requirements of time and space.
Programmer selects the best suited algorithm for the given task to be solved.

Characteristics of algorithm -

1. It should have finite number of steps.


2. The steps must be in order and simple.
3. Each step should be defined clearly stated i.e., without ambiguity.
4. Must include all required information.
5. Should exhibit at least one output.

Prepared by – Mr. Viral H. Panchal 15


Fundamentals of Programming (CE3002) Unit – 1: Introduction of Computer Programming

Different algorithms have different performance characteristics to solve the


same problem. Some algorithms are fast. Some are slow. Some occupy more
memory space. Some occupy less memory space. Some are complex and some
algorithms are simple.

Algorithm for preparing two cups of tea -

1. Add one and half cups of water to the vessel


2. Boil water
3. Add 2 tea spoons of tea leaves
4. Add half cup of milk
5. Add some sugar

Statement 5 is an example of an ambiguous (unclear) statement. This


statement doesn’t clearly state the amount of sugar to be added.

4.2. Flowchart
A flowchart is a pictorial (graphical) representation of an algorithm. A
flowchart is drawn using different kinds of symbols. A symbol is used for a
specific purpose. Each symbol has name.

Flowcharts use different shapes of boxes to denote different type of


instructions. ANSI recommended a number of different rules and guidelines to
help standardize the flowcharting process.

Flowchart helps to divide a large complex problem into small manageable


ones. Generally, algorithm is first represented as a flowchart and then
expressed in a programming language. While preparing a flowchart, the
sequence, selection and iterative structures may be used wherever required.

Rules for drawing flowchart -

1. It should contain only one start and one end symbol.


2. The relevant symbols must be used while drawing a flowchart.
3. The direction of arrows should be top to bottom and left to right.

Prepared by – Mr. Viral H. Panchal 16


Fundamentals of Programming (CE3002) Unit – 1: Introduction of Computer Programming

4. It should be simple and drawn clearly and neatly.


5. Be consistent in using names, variables in the flowchart.
6. Use properly labelled connectors to link the portions of the flowchart on
different pages.
7. The branches of decision box must be label.

Flowchart symbols –

1. Start and Stop:


Used to start flowchart as well as to terminate
flowchart.

2. Input / Output:

Used for input and output operation.

3. Process or expression representation:

Used to represent any assignment or expression.

4. Decision:

Used for any decision-making statement.

5. Direction of data flow or flow lines:

These arrows indicate the flow of sequence.

6. Connector:

Used for connecting flow lines from different places.

7. Loop:

Used for iteration or looping statement.

Prepared by – Mr. Viral H. Panchal 17


Fundamentals of Programming (CE3002) Unit – 1: Introduction of Computer Programming

Advantages of flowchart -

1. Conveys better meaning.


2. Analyses the problem effectively.
3. Good tool for documentation.
4. Provide guide for coding.
5. Systematic debugging.
6. Systematic testing.

Disadvantages of flowchart -

1. Takes more time to draw.


2. Difficult to make changes.
3. Non-standardization - No standards to determine how much details should
be included in a flowchart.

4.3. Programming Constructs / Programming Structures


There are three basic programming constructs or programming structures.
They are:

1. Sequence
2. Selection
3. Iteration (Loop)

Sequence -

Sequence logic is used for performing instructions one after another in


sequence.

• Sequence is the most basic of the constructs.


• It is simply performing one step after another.
• Each step is followed in a specific sequence, hence the name.
• Sequence can be thought of as “do this, then do this, then do this”.

Prepared by – Mr. Viral H. Panchal 18


Fundamentals of Programming (CE3002) Unit – 1: Introduction of Computer Programming

Figure 4.3.1: Sequence structure

Selection -

Selection logic, also known as decision logic, is used for making decisions.
Selection logic is depicted as either an if…then…else or if…then structure.

• Selection is the decision-making construct.


• It is used to make yes/no or true/false decisions logically.
• Selection can be thought of as “if something is true, take this action,
otherwise take that action”.

Figure 4.3.2: Selection structure

Prepared by – Mr. Viral H. Panchal 19


Fundamentals of Programming (CE3002) Unit – 1: Introduction of Computer Programming

Iteration (Loop) –

Iteration logic is also known as loop. Iteration logic is used when one or more
instructions may be executed several times depending on some condition.

• Iteration comes from the word “reiterate”, which means to repeat.


• Iteration is a looping construct.
• Iteration is a combination of decision and sequence and can repeat
steps.
• Iteration can be thought of as “while something is true, do this,
otherwise stop”.

Figure 4.3.2: Iteration (Loop) structure

Prepared by – Mr. Viral H. Panchal 20


Fundamentals of Programming (CE3002) Unit – 1: Introduction of Computer Programming

4.4. Algorithm and Flowchart Examples

• To find sum of two numbers.


Algorithm: Flowchart:

1. Start
2. Read A,B
3. C=A+B
4. Print or display C
5. Stop

• To Find area of the square.


Algorithm: Flowchart:

1. Start
2. Read length, L
3. Area = L*L
4. Print or display Area
5. Stop

Prepared by – Mr. Viral H. Panchal 21


Fundamentals of Programming (CE3002) Unit – 1: Introduction of Computer Programming

• To Find area of the rectangle.


Algorithm: Flowchart:

1. Start
2. Read side length, A
3. Read side length B
4. Area = A*B
5. Print or display Area
6. Stop

• Interchange the value of two numbers.


Algorithm: Flowchart:

1. Start
2. Read two values into two variables A, B
3. Declare third variable, C
4. C = A
5. A = B
6. B = C
7. Print or display A, B
8. Stop

Prepared by – Mr. Viral H. Panchal 22


Fundamentals of Programming (CE3002) Unit – 1: Introduction of Computer Programming

• Calculate the average for three numbers.


Algorithm: Flowchart:

1. Start
2. Read 3 numbers A, B, C
3. Calculate the average by the equation
Average = (A + B + C)/3
4. Print Average
5. Stop

• Find the largest of two numbers.


Algorithm: Flowchart:

1. Start
2. Read A,B
3. If A>B then
Print A is large
else
Print B is large
4. Stop

Prepared by – Mr. Viral H. Panchal 23


Fundamentals of Programming (CE3002) Unit – 1: Introduction of Computer Programming

• Find the sum of first five natural numbers.


Algorithm: Flowchart:

1. Start
2. Read n
3. Initialize count = 0, sum = 0
4. count = count + 1
5. sum = sum + count
6. Repeat steps 4 and 5 until count>=5
7. Print sum
8. Stop

• Calculate simple interest using the expression (SI=PNR/100).


Algorithm: Flowchart:

1. Start
2. Read P, N, R
3. SI=(P*N*R)/100
4. Print SI
5. Stop

Prepared by – Mr. Viral H. Panchal 24


Fundamentals of Programming (CE3002) Unit – 1: Introduction of Computer Programming

• Convert temperature from Fahrenheit to Celsius.


Algorithm: Flowchart:

1. Start
2. Initialize F = 0, C = 0
3. Read F
4. C = (F-32) * 5/9
5. Write C
6. Stop

• Calculate sum of integers 1 to 100.


Algorithm: Flowchart:

1. Start
2. Initialize count i = 1, sum = 0
3. sum = sum + i
4. Increment i by 1
5. Repeat steps 3 and 4 until i > 100
6. Print sum
7. Stop

Prepared by – Mr. Viral H. Panchal 25


Fundamentals of Programming (CE3002) Unit – 1: Introduction of Computer Programming

• Calculate factorial N where N! = 1 * 2 * 3 * … * N.


Algorithm: Flowchart:

1. Start
2. Read N
3. Initialize F = 1, I = 1
4. F = F * i
5. Increment i by 1
6. Repeat steps 4 and 5 until
i=N
7. Print F
8. Stop

Prepared by – Mr. Viral H. Panchal 26


Fundamentals of Programming (CE3002) Unit – 1: Introduction of Computer Programming

• Find the sum of n natural numbers.


Algorithm: Flowchart:

1. Start
2. Read n
3. Initialize Count = 0, Sum = 0
4. Count = Count + 1
5. Sum = Sum + Count
6. Repeat steps 4 until 5 until Count >= n
7. Print sum
8. Stop

Prepared by – Mr. Viral H. Panchal 27


Fundamentals of Programming (CE3002) Unit – 1: Introduction of Computer Programming

• Find the sum of all even numbers up to ‘n’.


Algorithm: Flowchart:

1. Start
2. Read n
3. Initialize Count = 0, Sum = 0
4. Count = count + 2
5. Sum = Sum + Count
6. Repeat steps 4 and 5 until count >= n
7. Print Sum
8. Stop

Prepared by – Mr. Viral H. Panchal 28


Fundamentals of Programming (CE3002) Unit – 1: Introduction of Computer Programming

• Find the product of N numbers.


Algorithm: Flowchart:

1. Start
2. Read n
3. Initialize Count = 0, Product = 1
4. Count = Count + 1
5. Product = Product * Count
6. Repeat steps 4 and 5 until count >= N
7. Print Product
8. Stop

Prepared by – Mr. Viral H. Panchal 29


Fundamentals of Programming (CE3002) Unit – 1: Introduction of Computer Programming

• Find the sum of squares of n natural numbers.


Algorithm: Flowchart:

1. Start
2. Read n
3. Initialize i = 0, Sum = 0
4. i = i + 1
5. Sum = Sum + (i * i)
6. Repeat steps 4 and 5 until i >= n
7. Print Sum
8. Stop

• Find the sum of first 50 odd numbers.


Algorithm: Flowchart:

1. Start
2. Initialize Sum = 0, N = 1
3. Sum= Sum + N
4. N = N + 2
5. Repeat steps 3 and 4 until N <= 99
6. Print Sum
7. Stop

Prepared by – Mr. Viral H. Panchal 30


Fundamentals of Programming (CE3002) Unit – 1: Introduction of Computer Programming

• Calculate percentage of marks.


Algorithm: Flowchart:

1. Start
2. Read Input data
3. Add marks of all subjects giving total
Obtained Marks
4. Percentage = ∗ 100
Total Marks

5. Write Percentage
6. Stop

• Flowchart to find whether given number is odd or even.

Prepared by – Mr. Viral H. Panchal 31


Fundamentals of Programming (CE3002) Unit – 1: Introduction of Computer Programming

• Flowchart to find maximum number from three different numbers.

• Flowchart to find root of equation: ax2 + bx + c.

Prepared by – Mr. Viral H. Panchal 32


Fundamentals of Programming (CE3002) Unit – 1: Introduction of Computer Programming

• Flowchart to reverse given number.

Prepared by – Mr. Viral H. Panchal 33


Fundamentals of Programming (CE3002) Unit – 1: Introduction of Computer Programming

• Flowchart to generate Fibonacci series up to given term.

Prepared by – Mr. Viral H. Panchal 34

You might also like