Programming Techniques and Logic Introductions
Programming Techniques and Logic Introductions
“There is no such thing as a problem without a gift for you in hand, you a seek problem because you need their gift”, If computer
problem solving can be demand in one word program, problem solving is a process requiring much though Careful, Planning,
Logical, Testing & Attention at the same time it can we challenging exciting and satisfying, experience the considerable room for
personal creativity.
The computer solution it is a set of instructions express in a programming language, a set of instructions is called program and
therefore correspond a solution to a problem.
Steps
Gathering the relevant information [Input] Processing the information [Processing] Arriving at the result [Output]
Find 3 numbers Add above numbers get the answer divide by 3
Pseudo code
A setup instruction to solve the problem is team as an Algorithm. Algorithm can be
express in different ways as follows;
The problem solving written in simple English which is called Pseudo code
Constant
Variable
Constant
Constant are data elements whose value cannot change during
program execution.
Ex – 22/7
Variable
Variables are data elements whose value change during the program execution, their two types as follows;
1. Alphanumeric
1
2. Numeric
Numeric (Integer)
Numeric variables are of two types as follows;
1. Integer
2. Float
Integer – Whole numbers (+ or -) its mention as Int
Float – Number with decimal places. Ex – xx.xxx
Declaring Variables
Each variable used in program must be declared, There are two way of variable declaration available. Special Characters are not
to initialize to variable.
Operators
Programs are required to perform a lot more than just simple input and output operation, these tools are known as operators.
Arithmetic Operators
Addition (+)
Subtraction ( – )
Multiplication (*)
Division (/)
Module (%) ex – 5 + 4 = 9 [ 4&5 Operation] [+ is operator]
Relational Operators
Operator Description
== Equal to
> Grater than
< Less than
!= Not Equal to
>= Grater than or Equal to
<= Less than or
Equal to
Logical Operators
1. Yes / No
2. True / False
3. On / Off
4. 1 / 0
2
Write the pseudocode for the following formula D = V * T you are requested to find out the Distance. In the above problem we
are concept the following factors, D = Distance, V = Velocity, T = Time.
Find the Velocity, Write the pseudocode V = U + FT, You can Find Out V
Condition
IF Condition
If a certain condition is true you direct the program to take one cause of affection is the condition is
false, you direct the program to do something else.
Nested IF Condition
Nested IF means, we use multiple IF Condition in one form, it has syntax as follows;
we use second if condition at the else statement of the First IF Condition.
1. Write the Pseudocode to accept 4 Marks of a Student and find the Total,
Average, and Grade and display the Total, Average and Grade using given
information.
2. Find out the Output of the following program.
Loop
One of the most important characteristics of a computer is its ability to execute a service of
instruction repeat. This cycle introduced the conceppt of Loop which allow the user grade flexibility in controlling the
number of time a specific task is to be repeater
3
While Loop
While Loop is a method, when the user use this Loop, there are user wish to use syntax, the syntax as follows;
In the following program we use the While Loop simply to give variety of outputs. Ex – 5 Then
1. Write the Pseudocode to input any 5 numbers and find their Accept (n) Number and Find (n) Number Sum
Sum? {
2. Write the Pseudocode to accept (n) number and Display Number == 0, Counter == 10, Sum ==0 Int;
reserve. Display “Please Enter (n) Positive Number”;
3. Write the Pseudocode to Adding 50 Numbers and display Sum. Accept Counter;
While (Counter => 0)
4. Write the Pseudocode to accept Positive (n) number and find
{
their Sum of (n) numbers. Accept Number While(Counter =<10)
5. Write the Pseudocode to Display the following {
Sum = Number + Sum;
This is Line Counter==Counter+1;
6. Write the Pseudocode to Given Output 4 1 Counter == Counter-1 Display “This..1”
7. Write the Pseudocode to accept 10 numbers 2 This is Line } Counter;
and Find their average and display that. 0 2 Display Sum; }
-2 This is Line }
While Statement -4 3
{
While Statement
While Statement
Counter, Number, Sum int;
{
{
Sum == 0;
Number int;
Number int;
Counter ==1;
Number == 10;
Number == 0;
While (Counter=<10)
Accept Number;
While (Number=>10)
{
While (Number=<0)
x` {
Accept Number;
{
Number == (Number +1)
Counter == Counter +1;
Number == (Number -1)
Display Number
Sum == Sum + Number;
Display Number
}}
Display Sum
}}
}}
4
5