PC Unit II Notes
PC Unit II Notes
PC Unit II Notes
Prepared by:
Ms. V. SWATHILAKSHMI / AP /CSE
UNIT II
I
C PROGRAMMING BASICS
Introduction to ‘ C’ Programming – Basic structure of a ‘C’ program – compilation
and linking processes – Constants, Variables – Data Types – Expressions using
operators in ‘C’ – Managing Input and Output operations – Decision Making and
Branching – Looping statements.
• Easy to learn
• Structured language
• It produces efficient programs.
• It can handle low-level activities.
• It can be compiled on a variety of computers.
History of C language
C is one of the most popular programming languages; it was developed by Dennis
Ritchie at AT & T‟s Bell Laboratories of USA in 1972.
C is a middle language
• Low level language-0 and 1‟s.
• High level language: eg FORTRAN, PASCAL, COBOL, BASIC,C, C++……etc.
• C stands in between these two categories. It is neither a low levellanguage nor a high level
language. It is a middle level language.
Features and applications of C language
• C is a general purpose, structured programming language.
• It is powerful, efficient, compact and flexible.
• It is highly portable.
• It is a robust language.
• C is a middle level language, i.e. it supports both the low level language and high level
language features.
• C language allows dynamic memory allocation.
• C programs are fast and efficient.
• C has got rich set of operators.
• It can be applied in systems programming areas like compilers,interpreters and assemblers,
etc.
The basic structure of a C program is divided into 6 parts which makes it easy to read,
modify, document, and understand in a particular format. C program must follow the below-
mentioned outline in order to successfully compile and execute. Debugging is easier in a well-
structured C program.
Sections of the C Program
There are 6 basic sections responsible for the proper execution of a program. Sections are
mentioned below:
1. Documentation
2. Pre-processor Section
3. Definition
4. Global Declaration
5. Main() Function
6. Sub Programs
1. Documentation
This section consists of the description of the program, the name of the program, and the
creation date and time of the program. It is specified at the start of the program in the form of
comments. Documentation can be represented as:
2. Pre-processor Section
All the header files of the program will be declared in the pre-processor section of the
program. Header files help us to access other’s improved code into our code. A copy of these
multiple files is inserted into our program before the process of compilation.
Example:
#include<stdio.h>
#include<math.h>
3. Definition
Pre-processors are the programs that process our source code before the process of
compilation. There are multiple steps which are involved in the writing and execution of the
program. Pre-processor directives start with the ‘#’ symbol. The #define pre-processor is used to
create a constant throughout the program. Whenever this name is encountered by the compiler, it
is replaced by the actual piece of defined code.
Example:
#define long long ll
4. Global Declaration
The global declaration section contains global variables, function declaration, and static
variables. Variables and functions which are declared in this scope can be used anywhere in the
program.
Example:
int num = 18;
5. Main () Function
Every C program must have a main function. The main() function of the program is written
in this section. Operations like declaration and execution are performed inside the curly braces of
the main program. The return type of the main() function can be int as well as void too. void()
main tells the compiler that the program will not return any value. The int main() tells the compiler
that the program will return an integer value.
Example:
void main()
or
int main()
6. Sub Programs
User-defined functions are called in this section of the program. The control of the program is
shifted to the called function whenever they are called from the main or outside the main()
function. These are specified as per the requirements of the programmer.
Example:
int sum(int x, int y)
{
return x+y;
}
Structure of C Program with example
Example: Below C program to find the sum of 2 numbers:
// Documentation
/*program to find sum.*/
#include <stdio.h> // Definition
#define X 20 // Global Declaration
int sum(int y); // Main() Function
int main(void)
{
int y = 55;
printf("Sum: %d", sum(y));
return 0;
}
// Subprogram
int sum(int y)
{
return y + X;
}
Output
Sum: 75
Explanation of the above Program
Sections Description
/*program to find sum. It is the comment section and is part of the description section of
*/ the code.
int main() main() is the first function that is executed in the C program.
Sections Description
These curly braces mark the beginning and end of the main
{…} function.
printf(“Sum: %d”, sum(y)); printf() function is used to print the sum on the screen.
The c compilation process converts the source code taken as input into the object code or
machine code. The compilation process can be divided into four steps, i.e., Pre-processing,
Compiling, Assembling, and Linking.
The pre-processor takes the source code as an input, and it removes all the comments from the
source code. The pre-processor takes the pre-processor directive and interprets it. For example,
if <stdio.h>, the directive is available in the program, then the pre-processor interprets the
directive and replace this directive with the content of the 'stdio.h' file.
The following are the phases through which our program passes before being transformed into an
executable form:
o Pre-processor
o Compiler
o Assembler
o Linker
Pre-processor
The source code is the code which is written in a text editor and the source code file is
given an extension ".c". This source code is first passed to the pre-processor, and then the pre-
processor expands this code. After expanding the code, the expanded code is passed to the
compiler.
Compiler
The code which is expanded by the pre-processor is passed to the compiler. The compiler
converts this code into assembly code. Or we can say that the C compiler converts the pre-
processed code into assembly code.
Assembler
The assembly code is converted into object code by using an assembler. The name of the
object file generated by the assembler is the same as the source file. The extension of the object
file in DOS is '.obj,' and in UNIX, the extension is 'o'. If the name of the source file
is 'hello.c', then the name of the object file would be 'hello.obj'.
Linker
Mainly, all the programs written in C use library functions. These library functions are
pre-compiled, and the object code of these library files is stored with '.lib' (or '.a') extension. The
main working of the linker is to combine the object code of library files with the object code of our
program. Sometimes the situation arises when our program refers to the functions defined in other
files; then linker plays a very important role in this. It links the object code of these files to our
program. Therefore, we conclude that the job of the linker is to link the object code of our program
with the object code of the library files and other files. The output of the linker is the executable
file. The name of the executable file is the same as the source file but differs only in their
extensions. In DOS, the extension of the executable file is '.exe', and in UNIX, the executable file
can be named as 'a.out'. For example, if we are using printf() function in a program, then the linker
adds its associated code in an output file.
CONSTANTS
The constants in C are the read-only variables whose values cannot be modified once
they are declared in the C program. The type of constant can be an integer constant, a floating
pointer constant, a string constant, or a character constant. In C language, the const keyword is
used to define the constants.
What is a constant in C?
As the name suggests, a constant in C is a variable that cannot be modified once it is declared in
the program. We can not make any change in the value of the constant variables after they are
defined.
How to define a constant in C?
We define a constant in C language using the const keyword. Also known as a const type qualifier,
the const keyword is placed at the start of the variable declaration to declare that variable as a
constant.
Syntax to Define Constant
Types of Constants in C
The type of the constant is the same as the data type of the variables. Following is the
list of the types of constants
• Integer Constant
• Character Constant
• Floating Point Constant
• Double Precision Floating Point Constant
• Array Constant
• Structure Constant
Properties of Constant in C
The important properties of constant variables in C defined using the const keyword are as
follows:
1. Initialization with Declaration
We can only initialize the constant variable in C at the time of its declaration. Otherwise, it will
store the garbage value.
2. Immutability
The constant variables in c are immutable after its definition, i.e., they can be initialized only once
in the whole program. After that, we cannot modify the value stored inside that variable.
VARIABLES
In C, a variable is a data name used for storing a data value. Its value may be changed
during program execution. The value of variables keeps on changing during the execution of a
program. In other words, a variable can be assigned different values at different times during the
execution of a program.
The variable can be of different data types. They can be integer, float or character data types.
These data are stored in the memory and at the time of execution different operations are
performed on them.
Variable declaration:
Syntax:
datatype v1,v2,v3,….,vn;
Description:
data_type - It is the type of data.
v1, v2, v3 ,…, vn - list of variables.
Example 1:
int regno;
float cgpa;
char name[10];
Variables are declared at three basic places:
• When the variables are declared inside a function, they are called local variables.
• When the variables are declared in the definition of function parameters, these variables are
called formal parameters.
• When the variables are declared outside all functions, they are called global
variables.“Variables used in expressions are also known as operands”
Initializing variables:
Initialization of variables can be done using the assignment operator(==).
Syntax:
Variable = constant;
Or
Datatype variable = constant;
Example:
A=5; B=8;
int i =23; float s=3.14;
Scope of variables
Scope of a variable implies the availability of variables within the program.
Two types:
• Local variables
• Global variables
(i)Local variable
Scope of a variable implies the availability of variables within the program..
Example
#include<stdio.h>
#include<conio.h>
void main()
/*local variable declaration */
int a,b;
int c;
/*actual initialization*/
a=10;
b=20;
c=a+b;
printf(“value of local variable\n a=%d\nb=%dc=%d\n”,a,b,c); getch();
}
Output
value of local variable a=10
b=20 c=30
Here all the variables a,b,c are local to main() function.
2.Global Variable
Global variable are variable defined outside the function, usually on the top of the program. The
global variable will hold their value throughout the lifetime of the program and it can be accessed
by the function defined in the program.
Example
#include<stdio.h>
#include<conio.h>
/*global variable declaration*/
int g;
void main()
int a,b;
clrscr();
/*actual initialization*/
a=10;
b=20;
g=a+b;
printf(“value of local variable\n a=%d\nb=%dg=%d\n”,a,b,g);
getch();
}
Output
value of local variable
a=10 b=20 g=30
DATA TYPES
Data type is the type of the data, that are going to access within the program. C supports
different data types, each data may have predefined memory requirement and storage
representation.
Example:
int roll, marks, age;
Float
Float data type is used to store numeric values with decimal point. In other words, float
data type is used to store real values, e.g. 3.14, 7.67 etc. e.g. percentage, price, pi, area etc. may
contain real values.
Char (Character)
Char (Character) data type is used to store single character, within singlequotes e.g. 'a', 'z','e' etc.
e.g. Yes or No Choice requires only 'y' or 'n' as an answer.
Type refers to an existing data type. New-type refers to the new user-defined data type.
Example: typedef int number;
Declare integer variables as: number roll, age, marks;It is equivalent to: int roll, age, marks;
Enum:
Enumeration (or enum) is a user defined data type in C. It is mainly used to assign names
to integral constants, the names make a program easy to read and maintain.
Array
An array is a collection of variables of same type i.e. collection ofhomogeneous data referred
by a common name. In memory, arrayelements are stored in a continuous location.
Syntax: datatype arrayname [Size of the array];
Pointer
A pointer is a special variable that holds a memory address (location inmemory) of another
variable.
* is a pointer variable. 'var_ name' is the name where the variable is tobe stored.
Example:
int a,*b; variable 'b' stores the address of variable 'a'.
Function:
A function in C is a set of statements that when called perform some specific task. It is the
basic building block of a C program that provides modularity and code reusability. The
programming statements of a function are enclosed within { } braces, having certain meanings and
performing certain operations. They are also called subroutines or procedures in other languages.
Struct
A struct is a user defined data type that stores multiple values of sameor different data types
under a single name. In memory, the entire structure variable is stored in sequence.
Syntax:
struct < structure name>
{
member1;member2;
};
2. Assignment operators Used to assign the values for the variable in C programs
5. Bitwise operators Used to perform bit operations on the given two variable
6. Conditional (ternary) operators Used to check whether the statement is true or false
1. Arithmetic operators
C arithmetic operators are used to perform mathematical calculations like addition,
subtraction, multiplication, division and modulus in c program.
1. + Addition A+B
2. - Subtraction A-B
3. * Multiplication A*B
4. / Division A/B
5. % modulus A%B
Example:
#include<stdio.h>
#include<conio.h>
void main()
{
int 40, b=20,
float add,sub,mul,div,mod;
clrscr();
add=a+b;
sub=a-b;
mul=a*b;
div=a/b;
mod=a%b;
printf(“Addition of a,b is:%d\n”,add);
printf(“Subtraction of a,b is:%d\n”,sub);
printf(“Multiplication of a,b is:%d\n”,mul);
printf(“Division of a,b is:%d\n”,div);
printf(“Modulus of a,b is:%d\n”,mod);
getch();
}
OUTPUT
Addition of a,b is:60
Subtraction of a,b is:20
Multiplication of a,b is:800
Division of a,b is:2
Modulus of a,b is:0
2. Assignment Operators
In C program, values for the variables are assigned using assignment operators
Compound Assignment
/= Sum/=10 This is same as sum=sum/10
Operators
Example:
#include<stdio.h>
#include<conio.h>
void main( )
{
int total=0,i;
for(i=0;i<10;i++)
{
total+=i;
}
printf("total=%d",total);
getch();
}
Output
Total=45
3. Relational operator
Relational operators are used to find the relation between two variables. i.e to compare the value of
two variables in a c program.
5. == x ==y x is equal to y
Example
#include<stdio.h>
#include<conio.h>
void main()
{
int m=40,n=20;
if(m==n)
{
printf("m and n are equal");
}
else
{
printf("m and n are not equal");
}
getch();
}
Output
m and n are not equal
1. Logical operators
These operators are used to perform logical operators on the given expression
Example
#include <stdio.h>
int main()
{
int a = 5, b = 5, c = 10, result;
result = (a == b) && (c > b);
printf("(a == b) && (c > b) is %d \n", result);
result = (a == b) && (c < b);
printf("(a == b) && (c < b) is %d \n", result);
result = (a == b) || (c < b);
printf("(a == b) || (c < b) is %d \n", result);
result = (a != b) || (c < b);
printf("(a != b) || (c < b) is %d \n", result);
result = !(a != b);
printf("!(a != b) is %d \n", result);
result = !(a == b);
printf("!(a == b) is %d \n", result);
return 0;
}
Output
(a == b) && (c > b) is 1
(a == b) && (c < b) is 0 (a == b) || (c < b) is 1
(a != b) || (c < b) is 0
!(a != b) is 1
!(a == b) is 0
4. Bitwise Operators
These operators are used to perform bitwise operations. Decimal values are converted into
binary values and bitwise operators work on these bits.
| bitwise OR
~ bitwise NOT
^ XOR
(Conditional expression?true_value:false_value);
Example
#include <stdio.h>
void main()
{
int x=1,y; y=(x==1?2:0);
printf("x value is %d\n",x);
printf("y value is %d",y);
getch();
}
Output
x value is 1
y value is 2
Syntax:
Increment operator: ++var_name (or) var_name++;
Decrement operator:--var_name (or)var_name--;
Example
#include<stdio.h>
#include<conio.h>
int main()
{
int a=10;
printf(“a++=%d\n”,a++);
printf(“++a=%d\n”,++a);
printf(“a--=%d\n”,a--);
printf(“--a=%d\n”,--a);
}
Output
a++=10
++a=12 a--=12
--a=10
7. Special Operator
C language supports some of the special operators they are
OPERATORS MEANING
, comma operators
EXPRESSION
An expression in C is a combination of operands and operators – it computes a single value
stored in a variable. The operator denotes the action or operation to be performed.
The operands are the items to which we apply the operation.
An expression can be defined depending on the position and number of its operator and
operands:
1. Infix Expression (operator is used between the operands) a=x+y
2. Postfix Expression (operator is used after the operands) xy+
3. Prefix Expression (operator is used before the operands) +xy
4. Unary Expression (one operator and one operand) x++
5. Binary Expression (one operator and two operands) x+y
Types of Expression
There are six types of expressions. These are shown below:
Arithmetic Expression
It consists of arithmetic operators ( + , - , * , and / ) and computes values of int, float, or
double type.
Relational Expression
It usually consists of comparison operators (> , < , >= , <= , === , and !== ) and computes
the answer in the bool type, i.e., true (1) or false (0).
Logical Expression
It consists of logical operators (&&, ||, and !) and combines relational expressions to compute
answers in the bool type.
Conditional Expression
It consists of conditional statements that return true if the condition is met
and false otherwise.
Pointer Expression
It may consist of an ampersand (&) operator and returns address values.
Bitwise Expression
It consists of bitwise operators ( >>, <<, ~, &, |, and ^ ) and performs operations at the bit
level.
• stdin: This file is used to receive the input (usually is keyborad file, but can also take input
from the disk file).
• stdout: This file is used to send or direct the output (usually is a monitor file, but can also
send the output to a disk file or any other device).
• stderr: This file is used to display or store error messages.
Input Ouput Statement
Input and Output statement are used to read and write the data in C programming. These
are embedded in stdio.h (standard Input/Output header file).
Input means to provide the program with some data to be used in the program and Output means
to display data on screen or write the data to a printer or a file.C programming language provides
many built-in functions to read any given input and to display data on screen when there is a need
to output the result.
There are mainly two of Input/Output functions are used for this purpose. These are discussed as:
• Unformatted I/O functions
• Formatted I/O functions
• getche()
getchar()
This function is an Input function. It is used for reading a single character from the keyboard. It is
a buffered function. Buffered functions get the input from the keyboard and store it in the memory
buffer temporally until you press the Enter key.
The general syntax is as:
v = getchar();
putchar(v);
char n;
n = getchar();
putchar(n);
}
gets()
This function is an input function. It is used to read a string from the keyboard. It is also a
buffered function. It will read a string when you type the string from the keyboard and press the
Enter key from the keyboard. It will mark null character (‘\0’) in the memory at the end of the
string when you press the enter key. The general syntax is as:
gets(v);
puts(v);
or
puts("text line");
where v is the variable of character type.
v = getch();
v = getche();
Formatted I/O functions which refers to an Input or Ouput data that has been arranged in a
particular format. There are mainly two formatted I/O functions discussed as follows:
• scanf()
• printf()
scanf()
The scanf() function is an input function. It used to read the mixed type of data from keyboard.
You can read integer, float and character data by using its control codes or format codes. The
general syntax is as:
or
Where arg1,arg2,……….argn are the arguments for reading and v1,v2,v3,……..vn all are the
variables.
The scanf() format code (specifier) is as shown in the below table:
Format Code Meaning
%c To read a single character
%d To read a signed decimal integer (short)
%ld To read a signed long decimal integer
%e To read a float value exponential
%f To read a float (short0 or a single precision value
%lf To read a double precision float value
%g To read double float value
%h To read short integer
%i To read an integer (decimal, octal, hexadecimal)
%o To read an octal integer only
%x To read a hexadecimal integer only
%u To read unsigned decimal integer (used in pointer)
%s To read a string
%[..] To read a string of words from the defined range
%[^] To read string of words which are not from the defined range
Example Program:
/*Program to illustrate the use of formatted code by using the formatted scanf() function */
#include <stdio.h>
main()
{
char n,name[20];
int abc;
float xyz;
printf("Enter the single character, name, integer data and real value");
scanf("\n%c%s%d%f", &n,name,&abc,&xyz);
getch();
}
printf()
This ia an output function. It is used to display a text message and to display the mixed type
(int, float, char) of data on screen. The general syntax is as:
or
Syntax:
if(condition is true)
{
Statement;
}
Example:
#include<stdio.h>
#include<conio.h>
void main()
{
int m,n,a;
clrscr();
printf(“Enter 2 numbers:”);
scanf(“%d%d”,&m,&n);
if(m>n)
{
a=m;
m=n;
n=a;
}
printf(“The interchanged values are: “%d%d”,m,n);
getch();
}
Flowchart:
Syntax:
if(condition is true)
{
True block;
}
else
{
false block;
}
Flowchart
Program:
#include<stdio.h>
main()
{
int a,b;
printf(“Enter two numbers:”);
scanf(“%d%d”,&a,&b);
if(a>b)
{
printf(“A is largest”);
}
else
{
printf(“B is largest”);
}
getch();
}
OUTPUT:
Enter two numbers:12 5
A is largest
(III) NESTED IF-ELSE STATEMENT
It is otherwise known as Two-way with sub-way decisions. If else statement is
enclosed within another if else structure. An if statement can be followed by an optional
else if...else statement, which is very useful to test various conditions using single if...else
if statement
Program:
#include<stdio.h>
main()
{
int a b c;
printf(“Enter the value for A, B and C:”);
scanf(“%d%d%d”,&a,&b,&c);
if((a>b)&&(a>c))
{
printf(“A is largest”);
}
else
{
if(b>c)
{
printf(“B is largest”);
}
else
{
printf(“C is largest”);
}
}
}
Output:
Enter the value for A,B and C:12 13 5
B is largest
Syntax:
if(condition 1)
{
if(condition 2)
{
True statement 2
}
else
{
False statement 2;
}
}
else
{
False statement 1;
}
Next Statement;
Flowchart
if(condition1)
statement 1;
else
if(condition 2)
statement 2;
else if(condition 3)
statement 3;
else
default statement;
Flowchart
Example:
#include<stdio.h>
#include<conio.h>
void main()
{
char x;
clrscr();
printf("Enter character: ");
scanf("%c",&x);
if(x>='a' && x<='z')
printf("Small letter");
else if(x>='A' && x<='Z')
printf("Capital letter");
else if(x>='0' && x<='9')
printf("Digit");
else
printf("Special Symbol");
getch();
}
LOOPING STATEMENTS
C LOOPS
The looping can be defined as repeating the same process multiple times until a specific
condition satisfies. There are three types of loops used in the C language.
Why use loops in C language?
The looping simplifies the complex problems into the easy ones. It enables us to alter the
flow of the program so that instead of writing the same code again and again, we can repeat the
same code for a finite number of times. For example, if we need to print the first 10 natural
numbers then, instead of using the printf statement 10 times, we can print inside a loop which runs
up to 10 iterations.
Advantage of loops in C
• It provides code reusability.
• sing loops, we do not need to write the same code again and again.
• Using loops, we can traverse over the elements of data structures (array or linkedlists).
Types of C Loops
There are three types of loops in C language that is given below:
• do while
• while
• for
DO WHILE LOOP IN C
The do while loop is a post tested loop. Using the do-while loop, we can repeat the
execution of several parts of the statements. The do-while loop is mainly used in the case where
we need to execute the loop at least once. The do-while loop is mostly used in menu-driven
programs where the termination condition depends upon the end user.
do while loop syntax
The syntax of the C language do-while loop is given below:
do{
//code to be executed
}while(condition);
Example 1
#include<stdio.h>
#include<stdlib.h>
void main ()
{
char c;
int choice,dummy;
do{
printf("\n1. Print Hello\n2. Print Javatpoint\n3. Exit\n");
scanf("%d",&choice);
switch(choice)
{
case 1 : printf("Hello");break;
case 2: printf("Javatpoint");break;
case 3:
exit(0);break; default:
printf("please enter valid choice");
}
printf("do you want to enter more?");
scanf("%d",&dummy);
scanf("%c",&c);
}while(c=='y');
}
Output
1. Print Hello
2. Print Javatpoint
3. Exit
1
Hello
do you want to enter more?
y
1. Print Hello
2. Print Javatpoint
3. Exit
2
Javatpoint
do you want to enter more?
n
WHILE LOOP IN C
While loop is also known as a pre-tested loop. In general, a while loop allows a part ofthe
code to be executed multiple times depending upon a given Boolean condition. It can be viewed as
a repeating if statement. The while loop is mostly used in the case where the number of iterations
is not known in advance.
Syntax of while loop in C language
The syntax of while loop in c language is given below:
while(condition){
//code to be executed
}
1
2
3
4
5
6
7
8
9
10
800
900
1000
• A conditional expression is used to check the condition. The statements defined inside the
while loop will repeatedly execute until the given condition fails.
• The condition will be true if it returns 0. The condition will be false if it returnsany non-
zero number.
• In while loop, the condition expression is compulsory.
• Running a while loop without a body is possible.
• We can have more than one conditional expression in while loop.
• If the loop body contains only one statement, then the braces are optional.
Example 1
#include<stdio.h>
void main ()
{
int j = 1;
while(j+=2,j<=10)
{
printf("%d ",j);
}
printf("%d",j);
}
Output
3 5 7 9 11
while(1){
//statement
}
FOR LOOP IN C
The for loop in C language is used to iterate the statements or a part of the programseveral
times. It is frequently used to traverse the data structures like the array and linked list.
Syntax of for loop in C
The syntax of for loop in c language is given below:
for(i=1;i<=10;i++)
{
printf("%d \n",i);
}
return 0;
}
Output
1
2
3
4
5
6
7
8
9
10
NESTED LOOPS IN C
C supports nesting of loops in C. Nesting of loops is the feature in C that allows the looping
of statements inside another loop. Let's observe an example of nesting loops inC.
Any number of loops can be defined inside another loop, i.e., there is no restriction for
defining any number of loops. The nesting level can be defined at n times. You can define any
type of loop inside another loop; for example, you can define 'while' loop inside a 'for' loop.
Syntax of Nested loop
Outer_loop
{
Inner_loop
{
// inner loop statements.
}
// outer loop statements.
}
Outer_loop and Inner_loop are the valid loops that can be a 'for' loop, 'while' loop or 'do-while'
loop.
Nested for loop
The nested for loop means any type of loop which is defined inside the 'for' loop.
for (initialization; condition; update)
{
for(initialization; condition; update)
{
// inner loop statements.
}
// outer loop statements.
}
• After the execution of the inner loop, the control moves back to the update ofthe outer loop,
i.e., i++.
• After incrementing the value of the loop counter, the condition is checked again,i.e., i<=n.
• If the condition is true, then the inner loop will be executed again.
• This process will continue until the condition of the outer loop is true.
Output:
Output:
Flow chart