0% found this document useful (0 votes)
239 views29 pages

Problem Solving Using C (Unit 1)

The document discusses several topics related to programming concepts: 1. It defines problem solving as determining the cause of a problem, identifying alternatives for a solution, implementing a solution, and monitoring the results. Problem solving generally involves 7 steps. 2. It introduces high-level programming languages like C and Pascal that are easier for humans to read and write than low-level assembly languages. 3. It defines an algorithm as a set of steps to solve a problem and provides examples of algorithms to add two numbers and find the largest of three numbers. It also introduces flowcharts to visually represent algorithms.
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)
239 views29 pages

Problem Solving Using C (Unit 1)

The document discusses several topics related to programming concepts: 1. It defines problem solving as determining the cause of a problem, identifying alternatives for a solution, implementing a solution, and monitoring the results. Problem solving generally involves 7 steps. 2. It introduces high-level programming languages like C and Pascal that are easier for humans to read and write than low-level assembly languages. 3. It defines an algorithm as a set of steps to solve a problem and provides examples of algorithms to add two numbers and find the largest of three numbers. It also introduces flowcharts to visually represent algorithms.
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/ 29

Approaches to problem solving:

Problem solving is the act of defining a problem; determining the cause of the problem;
identifying, prioritizing, and selecting alternatives for a solution; and implementing a solution.

It has following steps:

1. Define the problem.


2. Examine all potential causes for the problem.
3. Identify all alternatives to resolve the problem.
4. Carefully select an alternative.
5. Develop an orderly implementation plan to implement that best alternative.
6. Carefully monitor implementation of the plan.
7. Verify if the problem has been resolved or not.
High level programming language:
A high-level language (HLL) is a programming language such as C, FORTRAN, or Pascal that
enables a programmer to write programs that are more or less independent of a particular type
of computer. Such languages are considered high-level because they are closer to human
languages and further from machine languages.
In contrast, assembly languages are considered low-level because they are very close to
machine languages.

Advantages of High-Level Languages:


The main advantage of high-level languages over low-level languages is that they are easier to
read, write, and maintain. Ultimately, programs written in a high-level language must be
translated into machine language by a compiler or interpreter.
The first high-level programming languages were designed in the 1950s. Now there are dozens
of different languages, including Ada, Algol, BASIC, COBOL, C, C++, FORTRAN, LISP, Pascal,
and Prolog.
Concept of algorithm and flowchart:

Algorithm:
The word Algorithm means “a process or set of rules to be followed in calculations or other
problem-solving operations”. Therefore, Algorithm refers to a set of rules/instructions that step-
by-step define how a work is to be executed upon in order to get the expected results.
In programming, algorithm is a set of well-defined instructions in sequence to solve the
problem.

Attributes of a good algorithm

1. Input and output should be defined precisely.


2. Each steps in algorithm should be clear and unambiguous.
3. Algorithm should be most effective among many different ways to solve a problem.
4. It is not dependent on any programming language, so it is easy to understand for anyone even
without programming knowledge.
5. By using algorithm, the problem is broken down into smaller pieces or steps hence, it is easier
for programmer to convert it into an actual program

Write an algorithm to add two numbers entered by user.

Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values num1 and num2.
Step 4: Add num1 and num2 and assign the result to sum. sum←num1+num2
Step 5: Display sum
Step 6: Stop

Write an algorithm to find the largest among three different numbers entered by user.

Step 1: Start
Step 2: Declare variables a, b and c.
Step 3: Read variables a, b and c.
Step 4: If a>b If a>c Display a is the largest number. Else Display c is the largest number. Else If
b>c Display b is the largest number. Else Display c is the greatest number.
Step 5: Stop
Flowchart – A flowchart is a graphical or pictorial representation of an algorithm. Programmers
often use it as a program-planning tool to solve a problem. It makes use of symbols which are
connected among them to indicate the flow of information and processing.
Flowcharts are used in analyzing, designing, documenting or managing a process or program in
various fields. The Flowchart is an excellent way of communicating the logic of a program. It is
easy and efficient to analyze problem using flowchart.

Symbol of Flowchart- Flowcharts use special shapes to represent different types of actions or
steps in a process. Lines and arrows show the sequence of the steps, and the relationships
among them. These are known as flowchart symbols.

 Rectangle Shape – Represents a process


 Oval or Pill Shape – Represents the start or end
 Diamond Shape – Represents a decision
 Parallelogram – Represents input/output
Example:
Draw a flowchart to input two numbers from the user and display the largest of two numbers.
Structured programming:

Structured programming is a programming paradigm aimed at improving the clarity, quality,


and development time of a computer program by making extensive use of the structured
control flow constructs of selection (if/then/else) and repetition (while and for), block
structures, and subroutines.
Structured Programming Approach, as the word suggests, can be defined as a programming
approach in which the program is made as a single structure. It means that the code will execute
the instruction by instruction one after the other.
The structured program consists of well-structured and separated modules. But the entry and exit
in a Structured program is a single-time event. It means that the program uses single-entry and
single-exit elements. Therefore, a structured program is well maintained, neat and clean
program. This is the reason why the Structured Programming Approach is well accepted in the
programming world.

Advantages of Structured Programming Approach:


1. Easier to read and understand
2. User Friendly
3. Easier to Maintain
4. Mainly problem based instead of being machine based
5. Development is easier as it requires less effort and time
6. Easier to Debug
7. Machine-Independent, mostly.
History of C:
Salient features of C:

C is the widely used language. It provides many features that are given below.

1. Simple
2. Machine Independent or Portable
3. Mid-level programming language
4. structured programming language
5. Rich Library
6. Memory Management
7. Fast Speed
8. Pointers
9. Recursion
10. Extensible
Structure of C Program:
Compiling C Program, Link and Run C Program:
C Character set:
Tokens: Keywords, Identifiers, and Constants:
Variables and Data types:
Standard Input/Output:
Operators and expressions:

You might also like