C Programming Logic Building
C Programming Logic Building
By
Prof. SHIBDAS DUTTA
Associate Professor,
DCG DATA CORE SYSTEMS INDIA PVT LTD
Kolkata
Company Confidential: Data-Core Systems, Inc. |
Start-up
1. Can you list a serial generation language
programming?
2. The vocabulary of commonly spoken
communication is ________ the vocabulary of a
programming language?
a. Greater than b. Less than c. Equal to
3. What programming language do you like?
Chapter 1
Introducing to Programming Concept
Chapter 2
Representing the logic of Programming using Pseudocodes.
Chapter 3
Representing the logic of Programming using Flowcharts
Chapter 4
Understanding Iterations and Implementing Modular
Programming
condition) first and then, depending upon whether the value of the expression is
'true' (non-zero) or 'false' (zero), it transfers the control to a particular
statement.
Iterative: Instructions that are executed repeatedly, depending on the value
1000 010 11 1
01100101 011
0001 0 1 010 1 No need translater
(compiler)
The binary number system uses
the base of 2. For example, 101
in the binary system is equal to 5
in the decimal system. The
conversion can be done as:
101=1*22 + 0*21+ 1* 20 =1*4 +
0*2 + 1*1 = 4 + 0 + 1=5
NIIT Hai Company
Phong Confidential:
Software Data-Core
Park Systems, Inc. | 8
Assembly language
LD Ax, 9
LD Bx, 10 100 0 00
ADD Ax,Bx
Assembler 11
LD (100),Ax
JMP Bx 11 000 0 0
HLT 1 00 0 111
In the above program:
The line number one loads register Ax with the value, 9.
The line number two loads register Bx with the value, 10.
The line number three adds the value of register Bx to the value of register Ax.
The line number four stores the value of register Ax in the main memory
location, 100.
The line number five uses JMP to jump to register Bx to transfer the control to
register Bx.
The line number six stops the program execution.
be performed.
The steps in an algorithm specify basic operations.
It does not need to be rewritten if any changes are made because each step is
independent and may be modified without altering the other steps.
It can be converted to a program using any programming language.
Disadvantages of pseudocode are:
Pseudocode does not provide a graphical representation of an algorithm.
Pseudocode depicting too many nested conditions may be difficult to
understand.
It consists of a set of
symbols.
//: Comment
Naming conventions:
The first letter of the variable name might indicate the data type of the variable: cName
and nAge
The variable name should clearly describe the purpose of a variable: nScore
The variable name should not contain an embedded space or symbols such as ! @ # $ %
^ & * ( ) { } [ ] . , : ; “ ‘ / and \. You can use an underscore when a space is required in a
variable name, for example, nBasic_Salary.
If a variable name consists of multiple words without spaces in between, capitalize the
first letter of each word for readability. Some examples are nTotalScore and
nSumOfSquares.
Answer:
begin
accept cItem_name, nPrice, nQuantity,
nSale_value
nSale_value = nPrice * nQuantity
display cItem_name
display nSale_value
end
NIIT Hai Company
Phong Confidential:
Software Data-Core
Park Systems, Inc. | 34
Priority - Precedence
Operator Description Associativity Precedence
Level
() Parentheses 1
! Logical NOT 2
* Multiplication Left to right
/ Division 3
% Modulo division
+ Addition Left to right 4
- Subtraction
< Less than Left to right 5
<= Less than or equal to
Operator Precedence
NIIT Hai Company
Phong Confidential:
Software Data-Core
Park Systems, Inc. | 35
Conditional Execution
Many problems require decisions to be made.
All decisions may or may not state an action to be taken if
the condition is false.
The following types of decision-making constructs can be
used in an algorithm.
if constructs
switch…case constructs
switch (expression)
begin
case constant 1:
execute these statements
break
case constant 2:
execute these statements
break
default:
execute these statements
end
numeric nCall
accept nCall
Problem Statement 1:
Write a pseudocode to display the sum of two numbers by using
variables.
Solution:
begin
accept nNum1 //assigning values to variables
accept nNum2
nSum = nNum1 + nNum2
display nSum
end
Problem Statement 2:
Write a pseudocode where interest is calculated and displayed
for the given balance and rate.
Solution:
begin //start
accept Name, Balance, Rate //input
compute Interest as Balance x Rate //process
display Name and Interest //output
end //end
Problem Statement 3:
Write a pseudocode where a number is incremented by 1
Solution:
begin //starting
accept Number //input
compute Number as Number + 1 //process
display Number //output
end //end
for loop
goto
:
:
while (condition)
begin
:
:
end
:
:
:
:
repeat
begin
:
:
end until (condition)
:
Accept cStudentName
Accept
Average
Accept nTest1
Average nAverage=(nTest1+nTest2
Accept nTest2 +nTest3) / 3
Display cStudentName,
Accept nTest3 Return
nAverage
Is
nTest1>=0 AND Yes
nTest2>=0 AND
nTest3>=0 ?
No Return
Any questions?