Structured Programming
Structured Programming
COLLEGE OF ENGINEERING
2015/2016 SECOND SEMESTER
ENG 224: STRUCTURED COMPUTER PROGRAMMING WITH C
INSTRUCTORS:
Mr Ogunlade M. A.
COURSE DESCRIPTION
Weeks
Week 1
Week 2
Week 3
Week 4
Week 5
Week 6
Week 7
Week 8
Week 9
Week 10
Week 11
Week 12
Week 13
Phases
Phase 1
Phase 2
Topics
Algorithm, modular designs and sequence
Top-down, Bottom-up design flowchart
Pseduo Code, State Diagram
C Program Fund
User defined expressions and statements,
Exception handling, parameter passing method,
closures, continuation, and higher order functions
Project 2
REQUIREMENTS
Visual Studio express 2008 or higher
Laptops or Desktops
ICT Lab and Interactive Board
COURSE EVALUATION
Assignments, Attendance and Test: 40%
Final examination: 60%
Course Evaluation is subject to change without prior notification
Attendance
Project
1 2 3 4 5 6 7 8 9 10 10
Project 1
Test/Quiz
5 5 5 15
0 0 0
60
100
0
COURSE POLICIES
Late Assignment without a valid excuse will be lowered 10% for each day late. A late
assignment will not be accepted once the solution is discussed in class.
Collaboration is inappropriate in this course. However, you are encouraged to discuss
the assignment specifications with your instructors and your fellow students. anything
you submit for grading must be unique and should NOT be a duplicate of another
source. For collaboration assignment penalty will be failure.
Cell Phone: Do extend courtesy to your instructors and fellow students by turning off
your cell phones.
Attendance and Quiz: You are expected to attend all lectures except under very extreme
circumstances. Quiz will be conducted in class without prior notice.
Lecture notes are intended to serve as a supplement and not as a substitute for
attending
class.
Lateness to class after 15 Mins into the lecture will not be allowed without a valid
excuse.
The Instructors or Management reserves the right to modify course policies, course
calendar, course content, assignment values and due dates, as circumstances require.
`
SUGGESTED READINGS
C for Engineers and Scientist by Gary Bronson
C FOR Dummies 2nd edition by Dan Gookin
C Programming for Embedded Systems by Kirk Zurell
PART 1
C Programming Essentials By: K. N. Dey; S. K. Bandyopadhyay,
Safari Books Online
1.1 Programming
Programming is a required skill today, just like English and Mathematics. It teaches a
variety of skills that are important in all kinds of professions such as critical reading,
analytical thinking, creative synthesis, and attention to detail.
A PROGRAM is a set of instructions that a computer can follow to accomplish specific
task.
1.3. Algorithms
An algorithm is a well-defined computational procedure (sequence of computational
steps). It takes a set of values as its input and produces a set of values as its output. It
can be viewed as a utility for solving a computational problem.
There are a number of important features that must be satisfied by any algorithm:
Finiteness: This imposes that the algorithm must terminate after executing a
finite number of steps, i.e., it cannot run infinitely.
Input and Output: An algorithm has a domain of values, which initialize the
procedures. These are called the input values to the algorithm. It must also
generate a set of result values called output values.
Developing an Algorithm
Understand the problem (Do problem by hand. Note the steps)
Develop a plan (look for familiarity and patterns)
Carry out the plan (trace)
Review the plan (refinement)
Problem Example 1
Find the average of a given set of numbers.
Steps to Solution
2. Develop a plan:
Make note of what you did in steps (i) through (iv), but how you did it. In doing so,
you will begin to develop the algorithm.
e.g. How do we count the numbers?
Starting at 0 i.e. set COUNTER to 0
Look at 1st number, add 1 to COUNTER
Look at 2nd number, add 1 to COUNTER
and so on , until you reach the end of the list
How do we add numbers?
Let SUM be the sum of numbers in list. Set SUM to 0
Look at 1st number, add number to SUM
Look at 2nd number, add number to SUM
and so on, until we reach end of list
How do we compute the average?
Let AVE be the average
then AVE = total sum of items/number of items
i.e. SUM / COUNTER
10.
11.
12.
13.
14.
15.
16.
Add to sum
Get the fifth testscore
Add to sum
Get the sixth testscore
Add to sum
Output the sum
Stop
1.4. Flowcharts
A flowch1art is a graphic/pictorial representation of the steps necessary to solve a
problem, accomplish a task, complete a process, or illustrate the components of a
system.
The various flowchart symbols are explained as follows:
Oval/Rounded Rectangle: These symbols indicate the start or end of the program
as indicated by the text written inside the symbol.
Fig. 1.2 Flowchart for the Algorithm adding the test scores
Input/Output Instructions: A program needs input data from the external world
with which it performs operations on the input data, and generates output.
Input/output instructions, provide details on the type of input or output
operations to be performed, and the storage locations to be used during the
operations.
Control Instructions: These are selection and loop constructs, which aid in out-ofsequence program flow.
Although all programming languages have an instruction set that permits these familiar
operations to be performed, a marked difference is found between the symbols and
syntax used in machine languages, assembly languages, and high-level languages.
Each module involves processing of data that are logically related. Modules are
functional parts, which aid in processing. Ideally, each module works independent
of other modules, although this is sometimes impossible.
Modules are ranked by hierarchy and organized on the basis of importance. The
lower the module on the structure organization plan, more is the detail given to
the programming steps involved. The controlling module resides at the top level.
It gives the view of the overall structure for the entire program. The system is
designed to give more detail at each module level. A module is coded and tested,
and then tested with other tested modules. This procedure makes program
testing easier, since there is only one entry point and one exit point per module.
The modularization approach involves breaking a problem into a set of subproblems, followed by breaking each sub-problem into a set of tasks, then
breaking each task into a set of actions.
Example
Turn on a light bulb
-Sub-problem 1: locate bulb (one task, one action)
-Sub-problem 2: depress switch
Example
Given a list of students test scores, find the highest and lowest score and the
average score.
-Sub-problem 1: read students scores
-Sub-problem 2: find highest score
instructions that are to be executed when the condition is true follow the IF-THEN
alternative. The instructions followed by the ELSE alternative represent what is to
be executed when the condition is false. Figure (b) shows that if the condition is
true, the control will flow to function B and its statements will be executed; if it is
false, function A is executed. Another selection variation is the IF-THEN. It is used
when some operation is to be done only when the condition is true.
Repetition Structure: Repetition involves the use of a series of instructions that are
repeated until a certain condition is met. Repetition involves the use of two
variations the while and the do-while. The while performs a function as long as a
condition is true. On the other hand, do-while allows a function to be executed until
the given condition is false. Another marked difference is that the while first tests
the given condition and then executes the function, whereas do-while processes the
function before checking the condition. These are illustrated in Figure 1.3.
end-repeat
OR
while total < = 50 do:
read number
write number
end-while
Algorithm Average
This algorithm reads a list of numbers and computes their average.
Let: SUM be the total of the numbers read
COUNTER be the number of items in the list
AVE be the average of all the numbers
Set SUM to 0,
COUNTER to 0,
AVE to 0 (i.e. initialize variables)
While there is data do:
Read number
COUNTER = COUNTER + 1
(i.e. add 1 to COUNTER, storing result in COUNTER)
SUM = SUM + number
(i.e. add number to SUM, storing result in SUM)
end-while
if COUNTER = 0 then
AVE = 0
else
AVE = SUM/ COUNTER
Stop.
Exercises
1.
2.
5.
Write an algorithm that accepts a positive integer number, n, and calculate the
factorial of the number. Reject inputs less than 1 or greater than 17.
6.
7.
Write an algorithm that calculates all the elements of rows and columns of a
square matrix and calculate the total of primary and secondary diagonal.
8.
Write an algorithm that accepts two positive integer numbers n1 and n2 (n1 <
n2), and print the prime numbers in between n1 and n2, both inclusive.
9.
10.
PART 2
2.1 History of C Language
C has its origin in the early 1970, a project by AT&T Bell Labs, USA. Dennis Ritchie is
credited with defining and creating C. Many others also influenced the development of
the language. C is closely related to the UNIX operating system since it was developed
along with it. Most of the UNIX commands are written in C. Today, C has been
implemented on many different types of hardware and the language is used to tackle a
large class of programming problems.
#include <stdio.h>
int main()
{
printf("Hello Student, !\n");
return(0);
}
11. Scanf():scanf() is a function like printf(). Its purpose is to read text from the
keyboard.
12. Comment: are explanatory remarks made within a program. When used carefully,
comments can be very helpful in clarifying what the complete program is about, what
a specific group of statements is meant to accomplish, or what one line is intended to
do.
// comment
/* comment */
#include <stdio.h>
int main()
{
printf("Sum of student score is %d \n", 6 + 14 +10 + 13 + 30);
return(0);
}
This statement passes two arguments to the printf () function.
The first argument is the message Sum of student score is %d \n".The second argument
is the value of the expression 6 + 14 +10 + 13 + 30.
The first argument passed to printf ( ) must always be a message. A message that also
includes a conversion control sequence, such as %d. Conversion control sequences
have a special meaning to the printf ( ) function. They tell the function what type of
value is to be displayed and where to display it. A conversion control sequence always
begins with a % symbol and ends with a conversion character (c, d, f, etc.).
Example Average
#include <stdio.h>
int main()
{
printf("Average of student score is %d \n", (6 + 14 +10 + 13 +
30)/5);
return (0);
}
2.6 Variables
A variable is a symbolic name for a memory location in which data can be stored and
subsequently recalled. Variables are used for holding data values so that they can be
utilized in various computations in a program.
#include <stdio.h>
int main()
{
int PI = 3.14159;
int radius, area, circumference;
printf("Enter the radius in cm: ");
scanf_s("%f", &radius);
area = PI*radius*radius;
circumference = 2.0*PI*radius;
printf("The area is %f cm square.\n", area);
printf("The circumference is %f cm.\n", circumference);
return 0;
}
#include <stdio.h>
int main()
{
int num1, num2, num3;
float average;
printf("Enter the first numbers");
scanf_s("%d", &num1);
printf("Enter the second numbers");
scanf_s("%d", &num2);
printf("Enter the third numbers");
scanf_s("%d", &num3);
average = (num1 + num2 + num3) / 3.0;
printf("Average is %f", average);
return 0;
}
#include <stdio.h>
int main()
{
int num1, num2, num3;
float average;
printf("Enter the three numbers");
scanf_s("%d %d %d", &num1, &num2, &num3);
average = (num1 + num2 + num3) / 3.0;
printf("Average is %f", average);
return 0;
}
Example
Input/output operate to display first name, surname and matric number.
#include <stdio.h>
int main()
{
char sname[20];
char fname[20];
char matric[10];
printf("What is your surname?");
scanf_s("%s", sname);
printf("What is your firstname?");
scanf_s("%s", fname);
printf("What is your matric no?");
scanf_s("%s", matric);
printf("My name is %s, surname is %s and matric number
%s",sname,fname,matric);
return 0;
}
%s is the string placeholder
%i for integers placeholder
%f for double placeholder
Text Editor Text editor is used to edit plain text files, differ from word processors e.g.
Microsoft Word. A .doc file in a text editor contains tools to change fonts, margins, and
layout. Text editors, however, do not add formatting codes, which makes it easier to
compile your code.
Compiler is a computer program that transforms human readable source code of
another computer program into the machine readable code that a CPU can execute.
reads the instructions stored in the source code file, examines each instruction, and then
translates the information into the machine code understood only by the computers
microprocessor.
Source Code is the human readable instructions that a programmer writes.
Objects code is a portion of machine code that hasn't yet been linked into a complete
program.
Linker links several object (and library) files to generate an executable file. Links is a
computer program that takes one or more object files generated by a compiler and
combines them into a single executable program.
Library is a collection of implementations of behavior, written in terms of a
programming language, that has a well-defined interface by which the behavior is
invoked.
Executable file causes a computer "to perform indicated tasks according to encoded
instructions.
Identifiers are names used to identify variables, functions, or any other user-defined
item. An identifier starts with a letter A to Z or a to z or an underscore _ followed by
zero or more letters, underscores, and digits (0 to 9). C does not allow punctuation
characters such as @, $, and % within identifiers. C is a case sensitive programming
language. Thus, ABUAD and abuad are two different identifiers.
Example
mohd
zara
abc
_temp
a23b9
retVal
Keywords These are reserved words and may not be used as constant or variable or any other identifier names.
Auto
Else
Long
switch
Break
enum
Register
typedef
Case
extern
Return
union
Char
Float
Short
unsigned
Const
For
Signed
void
continue
Goto
Sizeof
volatile
Default
If
Static
while
Do
Int
struct
_Packed
Double
Integer Types
Following table gives you details about standard integer types with its storage sizes and
value ranges:
Type
Storage size
Value range
Char
1 byte
unsigned char
1 byte
0 to 255
signed char
1 byte
-128 to 127
Int
2 or 4 bytes
unsigned int
2 or 4 bytes
0 to 65,535 or 0 to 4,294,967,295
Short
2 bytes
-32,768 to 32,767
unsigned short
2 bytes
0 to 65,535
Long
4 bytes
-2,147,483,648 to 2,147,483,647
unsigned long
4 bytes
0 to 4,294,967,295
Floating-Point Types
Following table gives you details about standard floating-point types with storage sizes
and value ranges and their precision:
Type
Storage size
Value range
Precision
Float
4 byte
1.2E-38 to 3.4E+38
6 decimal places
Double
8 byte
2.3E-308 to 1.7E+308
15 decimal places
long double
10 byte
3.4E-4932 to 1.1E+4932
19 decimal places
A variable declaration provides assurance to the compiler that there is one variable
existing with the given type and name. Variable determines how much space it occupies
in storage. The type of a Variable Declaration in C:
Type
Description
Char
Int
Float
Double
Void
Example
#include <stdio.h>
int main()
{
/* variable definition: */
int a, b;
int c;
float f;
/* actual initialization */
a = 10;
b = 20;
c = a + b;
printf("value of c : %d \n", c);
f = 70.0 / 3.0;
printf("value of f : %f \n", f);
getchar();
return 0;
}
Variables are lvalues and so may appear on the left-hand side of an assignment.
Numeric literals are rvalues and so may not be assigned and cannot appear on the lefthand side. Following is a valid statement:
Example
a = 10; // Valid
10 = 20; //Not Valid
Integer literals
An integer literal can be a decimal, octal, or hexadecimal constant. A prefix specifies the
base or radix: 0x or 0X for hexadecimal, 0 for octal, and nothing for decimal.
An integer literal can also have a suffix that is a combination of U and L, for unsigned
and long, respectively. The suffix can be uppercase or lowercase and can be in any
order.
Examples
212
215u
0xFeeL
078
032UU
/*
/*
/*
/*
/*
Legal */
Legal */
Legal */
Illegal: 8 is not an octal digit */
Illegal: cannot repeat a suffix */
/*
/*
/*
/*
/*
/*
/*
decimal */
octal */
hexadecimal */
int */
unsigned int */
long */
unsigned long */
Floating-point literals
A floating-point literal has an integer part, a decimal point, a fractional part, and an
exponent part. You can represent floating point literals either in decimal form or
exponential form.
While representing using decimal form, you must include the decimal point, the
exponent, or both and while representing using exponential form, you must include the
integer part, the fractional part, or both. The signed exponent is introduced by e or E.
Here are some examples of floating-point literals:
3.14159
314159E-5L
510E
210f
.e55
/*
/*
/*
/*
/*
Legal */
Legal */
Illegal: incomplete exponent */
Illegal: no decimal or exponent */
Illegal: missing integer or fraction */
2.8.5 Operators
Arithmetic Operators
Following table shows all the arithmetic operators supported by C language. Assume
variable A holds 10 and variable B holds 20 then:
Examples
Operator Description
Example
A + B will give 30
B / A will give 2
++
--
#include <stdio.h>
main()
{
int a = 10;
int b = 20;
int c;
c = a + b;
printf("Line
c = a - b;
printf("Line
c = a * b;
printf("Line
c = a / b;
printf("Line
c = a % b;
printf("Line
c = a++;
printf("Line
c = a--;
printf("Line
}
Bitwise Operators
The Bitwise operators supported by C language are listed in the following table. Assume
variable A holds 60 and variable B holds 13 then:
Examples
Op
era Description
tor
&
Example
Binary XOR Operator copies the bit if it is set in one operand but
not both.
<<
Binary Left Shift Operator. The left operands value is moved left
by the number of bits specified by the right operand.
>>
#include <stdio.h>
main()
{
unsigned int
unsigned int
int c = 0;
c = a & b;
printf("Line
c = a | b;
printf("Line
c = a ^ b;
printf("Line
c = ~a;
printf("Line
c = a << 2;
printf("Line
c = a >> 2;
printf("Line
a = 60;
b = 13;
/* 60 = 0011 1100 */
/* 13 = 0000 1101 */
/* 12 = 0000 1100 */
1 - Value of c is %d\n",
/* 61 = 0011 1101 */
2 - Value of c is %d\n",
/* 49 = 0011 0001 */
3 - Value of c is %d\n",
/*-61 = 1100 0011 */
4 - Value of c is %d\n",
/* 240 = 1111 0000 */
5 - Value of c is %d\n",
/* 15 = 0000 1111 */
6 - Value of c is %d\n",
c);
c);
c);
c);
c);
c);
Assignment Operators
There are following assignment operators supported by C language:
Examples
Operator Description
Example
+=
C += A is equivalent to C = C + A
-=
C -= A is equivalent to C = C - A
*=
C *= A is equivalent to C = C * A
/=
C /= A is equivalent to C = C / A
%=
C %= A is equivalent to C = C % A
<<=
>>=
&=
^=
C ^= 2 is same as C = C ^ 2
|=
C |= 2 is same as C = C | 2
#include <stdio.h>
main()
{
int a = 21;
int c;
c = a;
printf("Line
c += a;
printf("Line
c -= a;
printf("Line
c *= a;
printf("Line
c /= a;
printf("Line
c = 200;
c %= a;
printf("Line
c <<= 2;
printf("Line
c >>= 2;
printf("Line
c &= 2;
printf("Line
c ^= 2;
printf("Line
c |= 2;
printf("Line
1 - =
Example
sizeof()
&
Pointer to a variable.
?:
Conditional Expression
#include <stdio.h>
main()
{
int a = 4;
short b;
double c;
int* ptr;
Relational Operators
Following table shows all the relational operators supported by C language. Assume
variable A holds 10 and variable B holds 20, then:
Examples
Operator Description
Example
==
Checks if the values of two operands are equal or not, if yes then condition
becomes true.
(A == B) is not true.
!=
Checks if the values of two operands are equal or not, if values are not equal
then condition becomes true.
(A != B) is true.
>
Checks if the value of left operand is greater than the value of right operand, if
(A > B) is not true.
yes then condition becomes true.
<
Checks if the value of left operand is less than the value of right operand, if
yes then condition becomes true.
>=
Checks if the value of left operand is greater than or equal to the value of right
(A >= B) is not true.
operand, if yes then condition becomes true.
<=
Checks if the value of left operand is less than or equal to the value of right
operand, if yes then condition becomes true.
#include <stdio.h>
main()
{
int a = 10;
int b = 20;
int c;
if (a == b)
{
printf("Line 1 - a is equal to b\n");
}
else
{
printf("Line 1 - a is not equal to b\n");
}
if (a < b)
{
printf("Line 2 - a is less than b\n");
}
else
{
(A < B) is true.
(A <= B) is true.
printf("Line 2
}
if (a > b)
{
printf("Line 3
}
else
{
printf("Line 3
}
/* Lets change value
a = 5;
b = 20;
if (a <= b)
{
printf("Line 4
}
if (b >= a)
{
printf("Line 5
}
b\n");
or equal to b\n");
Operators Precedence
Here operators with the highest precedence appear at the top of the table, those with
the lowest appear at the bottom. Within an expression, higher precedence operators will
be evaluated first.
Examples
Category
Operator
Associativity
Postfix
() [] -> . ++ - -
Left to right
Unary
Right to left
Multiplicative
*/%
Left to right
Additive
+-
Left to right
Shift
<< >>
Left to right
Relational
Left to right
Equality
== !=
Left to right
Bitwise AND
&
Left to right
Bitwise XOR
Left to right
Bitwise OR
Left to right
Logical AND
&&
Left to right
Logical OR
||
Left to right
Conditional
?:
Right to left
Assignment
Right to left
Comma
Left to right
#include <stdio.h>
main()
{
int a = 20;
int b = 10;
int c = 15;
int d = 5;
int e;
e = (a + b) * c / d;
// ( 30 * 15 ) / 5
printf("Value of (a + b) * c / d is : %d\n", e);
e = ((a + b) * c) / d;
// (30 * 15 ) / 5
printf("Value of ((a + b) * c) / d is : %d\n", e);
e = (a + b) * (c / d);
// (30) * (15/5)
printf("Value of (a + b) * (c / d) is : %d\n", e);
e = a + (b * c) / d;
// 20 + (150/5)
printf("Value of a + (b * c) / d is : %d\n", e);
return 0;
}
Logical Operators
Following table shows all the logical operators supported by C language. Assume
variable A holds 1 and variable B holds 0, then:
Examples
Operator
Description
Example
&&
Called Logical AND operator. If both the operands are non-zero, then condition
becomes true.
(A && B) is false.
||
(A || B) is true.
Called Logical NOT Operator. Use to reverses the logical state of its operand. If a
!(A && B) is true.
condition is true then Logical NOT operator will make false.
#include <stdio.h>
main()
{
int a = 5;
int b = 20;
int c;
if (a && b)
{
printf("Line
}
if (a || b)
{
printf("Line
}
/* lets change the
a = 0;
b = 10;
if (a && b)
{
printf("Line
1 - Condition is true\n");
2 - Condition is true\n");
value of a and b */
3 - Condition is true\n");
}
else
{
printf("Line 3 - Condition is not true\n");
}
if (!(a && b))
{
printf("Line 4 - Condition is true\n");
}
}
Description
if statement
if...else statement
switch statement
if statement Example
/* local variable definition */
int a = 10;
/* check the boolean condition using if statement */
if (a < 20)
{
/* if condition is true then print the following */
printf("a is less than 20\n");
}
printf("value of a is : %d\n", a);
2.9.2 Loops
A loop statement allows us to execute a statement or group of statements multiple times and following is the
general from of a loop statement in most of the programming languages:
Loop Type
Description
while loop
for loop
do...while loop
Like a while statement, except that it tests the condition at the end of the
loop body
#include <stdio.h>
int main()
{
/* local variable definition */
int a = 10;
/* while loop execution */
while (a < 20)
{
printf("value of a: %d\n", a);
a++;
}
return 0;
}
#include <stdio.h>
int main()
{
/* local variable definition */
int a = 10;
/* do loop execution */
do
{
printf("value of a: %d\n", a);
a = a + 1;
} while (a < 20);
return 0;
}
Description
break statement
continue statement
Causes the loop to skip the remainder of its body and immediately retest
its condition prior to reiterating.
goto statement
#include <stdio.h>
int main()
{
/* local variable definition */
int a = 10;
/* while loop execution */
while (a < 20)
{
printf("value of a: %d\n", a);
a++;
if (a > 15)
{
/* terminate the loop using break statement */
break;
}
}
return 0;
}
2.10.1
Functions
#include <stdio.h>
int main()
{
/* local variable definition */
int a = 10;
/* do loop execution */
do
{
if (a == 15)
{
/* skip the iteration */
a = a + 1;
continue;
}
printf("value of a: %d\n", a);
a++;
} while (a < 20);
return 0;
A function is a group of statements that together perform a task. Every C program has at least one function,
which is main(), and all the most trivial programs can define additional functions. Functions can be logically
division so each function performs a specific task.
A function declaration tells the compiler about a function's name, return type, and parameters.
A function definition provides the actual body of the function. The function definition consists of a function
header and a function body.
Return Type: A return_type is the data type of the value the function returns.
Function Name: The function name and the parameter list together constitute the function signature.
Parameters: A parameter is like a placeholder. The parameter list refers to the type, order, and number of the
parameters of a function. Parameters are optional; that is, a function may contain no parameters.
Function Body: The function body contains a collection of statements that define what the function does.
Example:
#include <stdio.h>
/* function declaration */
int max(int num1, int num2);
int main()
{
/* local variable definition */
int a = 100;
int b = 200;
int ret;
/* calling a function to get max value */
ret = max(a, b);
printf("Max value is : %d\n", ret);
return 0;
}
/* function returning the max between two numbers */
int max(int num1, int num2)
{
/* local variable declaration */
int result;
if (num1 > num2)
result = num1;
else
result = num2;
return result;
}
Math Functions
Although addition, subtraction, multiplication, and division are easily accomplished using C's arithmetic operators,
no such operators exist for raising a number to a power, finding the square root of a number, or determining
trigonometric values. To facilitate the calculation of powers, square roots, trigonometric, logarithmic, and other
mathematical calculations frequently required in scientific and engineering programs, C provides standard
preprogrammed functions that can be included in a program.
See table for more details
Step
1.Perform multiplication in argument
2.Complete argument calculation
3.Return a function value
4.Perform the multiplication
5.Perform the division
2.10.2
Result
3.0* sqrt(165 - 13.71)/ 5
3.0* sqrt(151.290000) / 5
3.0* 12.300000/ 5
36.900000/ 5
7.380000
Scope Rules
A scope in any programming is a region of the program where a defined variable can have its existence and
beyond that variable cannot be accessed. There are three places where variables can be declared in C
programming language:
1.
2.
3.
Local Variables
Variables that are declared inside a function or block are called local variables. They can be used only by
statements that are inside that function or block of code. Local variables are not known to functions outside their
own. Following is the example using local variables.
Global Variables
Global variables are defined outside of a function, usually on top of the program. The global variables will hold
their value throughout the lifetime of your program and they can be accessed inside any of the functions defined
for the program.
Formal Parameters
Formal parameters, are treated as local variables within that function and they will take preference over the
global variable.