Unit 1 Data Structrure
Unit 1 Data Structrure
(CSA2101)
Presidency School of Computer Science and
Engineering
Assessment Schedule
Course Duratio
S. Assessment Mark Weighta
Contents Outcome n In DATE
No type s ge
Number Hours
Continuous
1 Assessment 1
Module 1 CO1 55 Mins 10 5% 09.02.25
Continuous
2 Assessment 2 Module 2 CO2 55 Mins 10 5% 28.02.25
3 Assignment 1 Module 1 & 2 CO1 & CO2 One Week 5 2.5% 03.03.25
17.03.25 to
4 Mid Term Module 1 & 2 CO1 & CO2 90 Mins 50 25%
21.03.25
Continuous
5 Assessment 3
Module 3 CO3 55 Mins 10 5% 25.03.25
Continuous
6 Assessment 4
Module 4 CO4 55 Mins 10 5% 12.04.25
7 Assignment 2 Module 3 & 4 CO3 & CO4 One Week 5 2.5% 30.04.25
if Statement
if-else Statement
Nested if Statement
if-else-if Ladder
switch Statement
Conditional Operator
Jump Statements:
break
continue
goto
return
Decision Control Statements (Revision of C Concepts)
Decision control statements alter the normal sequential execution of the statements of the
program depending upon the test condition to be carried out at a particular point in program.
if (condition) if (condition)
{
{ statement (s);
statement 1; }
statement 2;
} Next Statement
statement 3;
In above syntax : if condition is true only then the statements within the block
are executed otherwise next statement in sequence is executed.
if statement flowchart /* Program to check whether a no. is even */
# include<stdio.h>
# include<conio.h>
void main()
False {
Condition int num;
clrscr();
True printf(“enter the number”);
scanf(“%d”,&num)
Block of
if(num%2==0)
if
{
}
if – else statement (Revision of C Concepts)
In case of if statement, the block of statements is executed only when the condition is true
otherwise the control is transferred to the next statement following if block.
But if specific statements are to be executed in both cases (either condition is true or false) then if –
else statement is used.
In if – else statement a block of statements are executed if the condition is true but a different block
of statements is executed when the condition is false.
Syntax:
if (condition)
{
False
statement 1; Test
statement 2; Condition
}
else
True
{
statement 3; Block of if Block of else
}
Next statement
STOP
if else example(Revision of C Concepts)
#include <stdio.h>
int main()
{ int n = 10;
if (n > 5)
{
printf("%d is greater than 5",n);
}
else
{
printf("%d is less than 5",n);
}
return 0;
}
If- else- if ladder (Revision of C Concepts)
In a program involving multiple conditions, the nested if else statements makes the program very difficult
to write and understand if nested more deeply.
For this ,we use if-else-if ladder.
Syntax:
if (condition1)
statement1;
else if(condition2)
false
statement2;
condition 1
else if(condition3)
false
statement 3;
condition 2
else true
false
default statement;
Statement 1 true condition 3
Statement 2 true
Statement 3
Default statemen
Next statement
if else ladder example(Revision of C Concepts)
{ printf("C\n");
} else if (marks >= 60)
int marks = 85;
{
// Assign grade based on marks
printf("D\n");
if (marks >= 90)
} else
{ {
printf("A\n"); printf("F\n");
} else if (marks >= 80) }
{ return 0;
printf("B\n"); }
}
Looping Structures (Revision of C Concepts)
1.Entry Controlled loops: In Entry controlled loops the test condition is checked before
entering the main body of the loop. For Loop and While Loop is Entry-controlled loops.
2.Exit Controlled loops: In Exit controlled loops the test condition is evaluated at the
end of the loop body. The loop body will execute at least once, irrespective of whether
the condition is true or false. do-while Loop is Exit Controlled loop.
Looping Structures (Revision of C Concepts)
When we want to repeat a group of statements a no. of times, loops are used.
When condition becomes false, control terminates the loop and moves on to next
instruction immediately after the loop.
Various looping structures are-
While
do – while
for
Looping Statements (Revision of C Concepts)
Loop is divided into two parts:
Body of the loop
Control of loop
While loop is used to execute set of statements as long as condition evaluates to true.
It is mostly used in those cases where the programmer doesn’t know in advance how
many times the loop will be executed.
Syntax:
while (condition)
{
Statement 1 ;
Statement 2 ;
}
condition true statement
#include <stdio.h>
int main()
{
int i = 1;
// Condition for the loop
while (i <= 5)
{
printf(“I Love Presidency University\n");
// Increment i after each iteration
i++;
}
return 0;
}
do- while (Revision of C Statements)
do-while is similar to while except that its test condition is evaluated at the end of the loop
instead at the beginning as in case of while loop.
So, in do-while the body of the loop always executes at least once even if the test
condition evaluates to false during the first iteration.
Syntax:
do
{
statement 1;
statement 2;
}while (condition); Body of loop
statement;
true
Test condition
false
Next statement
do- while example (Revision of C Statements)
#include <stdio.h>
int main()
{
int i = 0;
// do while loop
do
{
printf("Geeks\n");
i++;
}
while (i < 3);
return 0;
}
for loop (Revision of C Concepts)
Is used in those situations when a programmer knows in advance the number of times a
statement or block will be executed.
It contains loop control elements all at one place while in other loops they are scattered over
the program and are difficult to understand.
Syntax:-
for (initialization; condition; increment/decrement)
{
Statement( s);
}
Various other ways of writing same for loops(Revision of C
Concepts)
A function in C is a set of statements that when called perform some specific tasks. C
function contains set of instructions enclosed by “{ }” which performs specific
operation in a C program.
A function will carry out its intended task whenever it is called or invoked
n be called multiple times
Example
A function to add two numbers
A function to find the largest of n numbers
What is C Function? (Revision of C Concepts)
Execution of the program always begins by carrying out the instructions in main
Functions call other functions as instructions
Function Declaration, Function Call and Function Definition
(Revision of C Concepts)
Function declaration or prototype – This informs compiler about the function name,
function parameters and return value’s data type.
// Function declaration
int add(int a, int b);
int main() {
int num1, num2, result;
// Function calling
result = add(num1, num2);
return 0;
}
// Function definition
int add(int a, int b) {
return a + b;
}
Example of Function for addition of two numbers
(Revision of C Concepts)
// C program to show function
// call and definition
#include <stdio.h>
// Function that takes two parameters a and b as inputs and returns their sum
// Driver code
int main()
{
// Calling sum function and storing its value in add variable
int add = sum(10, 30);
printf("Sum is: %d", add);
return 0;
}
Explanation:
Function declaration: int add(int a, int b);
Function definition: Logic for addition is
written in the add() function.
Function calling: Called from main().
Conditions of Return Types and
Arguments
In C programming language, functions can be called either with or
without arguments and might return values. They may or might not
return values to the calling functions.
1.Function with no arguments and no return value
Data on its own is useless unless you can make sense of it!
What is Data Structure?
Data structure
Primitive DS Non-Primitive DS
Non-Primitive DS