Unit 1
Unit 1
The mental activity for abstracting problems and formulating solutions that can be
automated
Computational thinking is the step that comes before programming. It’s the process of
breaking down a problem into simple enough steps that even a computer would
understand.
Purpose of CT
1. CT can be applied by anyone who is attempting to solve a problem and have a computer
play a role in the solution.
4. CT enables us to take large problems and break them into simpler steps can help with
everything from solving
1. Socrates is a man.
2. All men are mortal.
3. Therefore, Socrates is mortal.
logic is a system used for distinguishing between correct and incorrect arguments.
we mean the philosophical idea of an argument; namely a chain of reasoning that ends up in a
conclusion.
Inductive arguments
Inductive reasoning is a logical thinking process in which specific observations that are believed
to be true are combined to draw a conclusion to create broader generalizations and theories
Example :
1. Socrates is a man.
2. All men are mortal.
3. Therefore, Socrates is mortal.
Deductive arguments
Deductive reasoning, on the other hand, works in the opposite direction of inductive reasoning. It
is a logical thinking process that uses the top-down approach to go from the more general to the
more specific
Algorithm:
Definition: An algorithm is a step-by-step method for solving some problem. An algorithm
refers to a set of instructions that define the execution of work to get the expected results.
To make the program work properly, we must have to properly design the algorithm.
Designing the algorithm helps to utilize the computing resources effectively.
It uses plain text, which is written in plain English language.
The algorithm is easy to debug.
There are no rules employed for algorithms.
Algorithms are the program's pseudo-code
.
Flowchart
Definition: A diagrammatic representation of an algorithm is called a flow chart.
A flowchart is a graphical representation of an algorithm.
A flowchart can be helpful for both writing programs and explaining the program to
others.
A flowchart is a diagram created with different shapes to show the flow of data.
It uses various symbols to show the operations and decisions to be followed in a program
The process of drawing a flowchart for an algorithm is known as “flowcharting”
Oval
Parallelogram
Rectangle
Diamond
Circle
Arrows
Double
Sided Rectangle
Pentagon
Hexagon
Printout
pseudocode
Pseudocode is a simple way of writing programming code in English
Pseudocode is not actual programming language. It uses short phrases to write code for
programs before you actually create it in a specific language
Examples of Pseudocode
1. pseudocode to create a program to add 2 numbers together and then display the
result
Start Program
Enter two numbers, A, B
Add the numbers together
Print Sum
End Program
Enter length, l
Enter width, w
Compute Perimeter = 2*l + 2*w
Display Perimeter of a rectangle
Remember, writing a basic pseudocode is not like writing an actual coding language.
It cannot be compiled or run like a regular program.
Top-down Approach start from main() function and go to the respective function down the
order. So, basically all C program execution start from top the order i.e; from main() function
and go to down the order, i.e; it is said as top-down approach. Here is the pictorial view:-
#include<stdio.h>
void main()
{
int a,b;
clrscr();
printf("Enter Two Number : ");
scanf("%d%d",&a,&b);
sum(a,b);
getch();
}
sum(int x,int y)
{
int z;
z=x+y;
printf("Sum of Two Number is : %d",z);
return 0;
}
Structured programming
1. Structured programming generally makes use of top-down design because program
structure is divided into separate subsections
2. Structured programming (sometimes known as modular programming) is a programming
paradigm that facilitates the creation of programs with readable code and reusable
components
3. C is called structured programming language because a program in c language can be
divided into small logical functional modules or structures with the help of function
procedure.
4. It encourages top-down implementation, which improves both readability and
maintainability of code.
5. Structured programming encourages dividing an application program into a hierarchy of
modules
6. Structured programming languages are simple and easy to understand because
programmers do not require knowing complex design concepts to start a new program.
Interpreter
Interpreter is also used to perform the same function. But the only difference is that
compiler translates the whole program at once while the interpreter converts each line
individually.
Runtime Error
Output :
Logical Errors
Let suppose if we want sum of the 2 numbers but given output is the multiplication of 2
numbers then this said to be Logical error.
It can be detected by line by line debugging.
Output
Sum is 200
Debugging
called as ‘bugs’) in a program code that can cause it to behave unexpectedly or crash.
Debugging tools (called debuggers) are used to identify coding errors at various
development stages. They are used to reproduce the conditions in which error has
occurred, then examine the program state at that time and locate the cause.
Programmers can trace the program execution step-by-step by evaluating the value of
variables and stop the execution wherever required to get the value of variables or reset
Some programming language packages provide a debugger for checking the code for