0% found this document useful (0 votes)
43 views27 pages

Template CTSD-1

Uploaded by

het838225
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views27 pages

Template CTSD-1

Uploaded by

het838225
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 27

FACULTY OF ENGINEERING & TECHNOLOGY

BACHELOR OF TECHNOLOGY

Computational Thinking for Structure Design -


1 (303105104)
1st SEMESTER
COMPUTER SCIENCE & ENGINEERING
DEPARTMENT

Laboratory
Manual

COMPUTATIONAL THINKING FOR STRUCTURE DESIGN -1 PRACTICAL BOOK


Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1

COMPUTER SCIENCE AND ENGINEERING DEPARTMENT

PREFACE

It gives us immense pleasure to present the first edition of Computational Thinking for
Structure Design -1 for the B.Tech. 1st year students for PARUL UNIVERSITY.

The Fundamental of Programming theory and laboratory courses at PARUL


UNIVERSITY, WAGHODIA, VADODARA are designed in such a way that students develop
the basic understanding of the subject in the theory classes and then try their hands on the computer
learnt during the theoretical sessions.
This book is emphatically not focused on “the syntax of C”. Understanding the fundamental
ideals, principals, and techniques is the essence of a good programmer. Only well-designed code
has a chance of becoming part of a correct, reliable, and maintainable system. Also, “the
fundamentals” are what last: they will still be essential after today’s language and tools have
evolved or been replaced.
We acknowledge the authors and publishers of all the books which we have consulted while
developing this Practical book. Hopefully this Computational Thinking for Structure Design -1 will
serve the purpose for which it has been developed.

Enrollment No: Page No:


Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1

Instructions to students

1. Every student should obtain a copy of laboratory Manual.


2. Dress Code: Students must come to the laboratory wearing.
i. Trousers,
ii. half-sleeve tops and
iii. Leather shoes. Half pants, loosely hanging garments and slippers are not allowed.
3. To avoid injury, the student must take the permission of the laboratory staff before handling any
machine.
4. Students must ensure that their work areas are clean and dry to avoid slipping.
5. Do not eat or drink in the laboratory.
6. Do not remove anything from the computer laboratory without permission.
7. Do not touch, connect or disconnect any plug or cable without your lecturer/laboratory
technician’s permission.
8. All students need to perform the practical/program.

Enrollment No: Page No:


Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1

Faculty of Engineering & Technology (FET)

Parul Institute of Engineering & Technology (PIET)


Department of Computer Science & Engineering

CERTIFICATE

This is to certify that Mr./Ms. Deepakkumar Ravindar Sharma


UG No.24UG035720 & Enrolment No. has completed
all the practicals of the subject on his/her own and is submitting the lab manual with proper formatting as per
the given instructions. His/Her work is found satisfactory and hence, he/she has successfully completed the
term-work submission of Computational Thinking for Structured Design - 1 (303105104) for the Term &
Academic Year 2024-25 (Odd Semester).

Date of Submission:

Student’s Signature Subject Faculty’s Signature

HoD’s Signature

Enrollment No: Page No:


Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1

INDEX

Class: 1st Sem Subject: - Computational Thinking for Structured Design-1


A.Y. 2024-2025 Subject Code: 303105104

Practical Assessment Table

Sr. Page No. Marks


Practical Title Sign
No. (10)
From To

1 Practical – 1 (Introduction to C Language)

2 Practical – 2 (Basic C Programs with I/O)

3 Practical – 3 (Branching Statements)

4 Practical – 4 (While & Do-While Statements)

5 Practical – 5 (For Loop Programs)

6 Practical – 6 (Nested For Loop Programs)

7 Practical – 7 (1D & 2D Array Programs)

8 Practical – 8 (String Handling Programs)

9 Practical – 9 (User Defined Functions)

Term Work Submission

CTSD - 1

Enrollment No: Page No:


Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1

Practical 1
Introduction to C Language

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:

a. Documentation
b. Preprocessor Section
c. Definition
d. Global Declaration
e. Main() Function
f. 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:

// description, name of the program, programmer name, date, time etc.


/*
description, name of the program, programmer name, date, time etc.
*/
Anything written as comments will be treated as documentation of the program and this will not
interfere with the given code. Basically, it gives an overview to the reader of the program.

2. Preprocessor Section
All the header files of the program will be declared in the preprocessor 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:

Enrollment No: 24UG035720 Page No:


Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
#include<stdio.h>
#include<math.h>

3. Definition
Preprocessors 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.
Preprocessor directives start with the ‘#’ symbol. The #define preprocessor 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)

Enrollment No: 24UG035720 Page No:


Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
{
return x+y;
}

List of Format Specifiers in C


The below table contains the most commonly used format specifiers in C

Format Specifier Description

%c For char type.

%d For signed integer type.

%e or %E For scientific notation of floats.

%f For float type.

%g or %G For float type with the current precision.

%i Unsigned integer

%ld or %li Long

%lf Double

%Lf Long double

%lu Unsigned int or unsigned long

%lli or %lld Long long

%llu Unsigned long long

%o Octal representation

%p Pointer

%s String

Enrollment No: 24UG035720 Page No:


Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
Format Specifier Description

%u Unsigned int

%x or %X Hexadecimal representation

%n Prints nothing

%% Prints % character

Escape Sequence List

The table below lists some common escape sequences in C language.

Escape
Sequence Name Description

\a Alarm or Beep It is used to generate a bell sound in the C program.

\b Backspace It is used to move the cursor one place backward.

It is used to move the cursor to the start of the next


\f Form Feed
logical page.

\n New Line It moves the cursor to the start of the next line.

\r Carriage Return It moves the cursor to the start of the current line.

It inserts some whitespace to the left of the cursor and


\t Horizontal Tab
moves the cursor accordingly.

\v Vertical Tab It is used to insert vertical space.

\\ Backlash Use to insert backslash character.

\’ Single Quote It is used to display a single quotation mark.

\” Double Quote It is used to display double quotation marks.

Enrollment No: 24UG035720 Page No:


Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
Escape
Sequence Name Description

\? Question Mark It is used to display a question mark.

\ooo Octal Number It is used to represent an octal number.

Hexadecimal
\xhh It represents the hexadecimal number.
Number

\0 NULL It represents the NULL character.

1.1

Input:-

Output:-

Enrollment No: 24UG035720 Page No:


Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1

1.2

Input:-

Output:-

1.3
Input:-

Output:-

Enrollment No: 24UG035720 Page No:


Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1

1.4
Input:-

Output:-

1.5
Input:-

Ouput:-

Conclusion:-

Enrollment No: 24UG035720 Page No:


Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
Practical 2

Basic C Programs with I/O

Practical 2 on basic C programs with input and output (I/O) involves writing programs to demonstrate the
use of various input and output functions, expressions, and functional blocks. Here are some examples of
I/O functions in C:

printf()
printf is a C function belonging to the ANSI C standard library, and included in the file stdio. h. Its purpose
is to print formatted text to the standard output stream. Hence the "f" in the name stands for "formatted". It
takes the following unusual syntax: printf(string format, items-to-format).

scanf().
The scanf function in C is a standard library function that reads and parses text from the standard input
device, usually the keyboard. It allows the program to pause and wait for the user to enter data. The
function's name is short for "scan formatted".

Here are the steps to write a C program to demonstrate I/O functions:

1)Start the program.


2)Declare and initialize all required variables.
3)Get input values from the user for arithmetic operation.
4)Use the input function scanf() and the output function printf() to display the output after the calculation.
5)Stop the program .

2.1

Input:-

Output:-

Enrollment No: 24UG035720 Page No:


Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1

2.2

Input:-

Output:-

2.3

Enrollment No: 24UG035720 Page No:


Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
Input:-

Output:-

2.4

Enrollment No: 24UG035720 Page No:


Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
Input:-

Output:-

2.5

Enrollment No: 24UG035720 Page No:


Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
Input:-

Output:-

Conclusion:-

Enrollment No: 24UG035720 Page No:


Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
Practical 3
Branching Statements

A branching statement is a computer program instruction that changes the order of instructions executed. It
allows the program's flow of execution to jump to a different part of the program. Branching statements are
used to control the flow of control based on conditions, which helps guide the program's decision-making
process. The common branching statements used within other control structures include: break , continue ,
return , and goto . The goto is rarely used in modular structured programming.
Here are its types:

Break and continue statements


These are branching statements or jump statements in C that can be used inside any loop. They can be used
to skip some statements or immediately terminate the loop when the condition is satisfied.

Switch and case statements


These statements help control complex conditional and branching operations in C. The switch statement
transfers control to a statement within its body.

Multiway branch
This is a form of conditional statement in C that is often the most efficient method of passing control to one
of a set of program labels.

3.1

Input:-

Ouput:-

Enrollment No: 24UG035720 Page No:


Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1

3.2

Input:-

Output:-

Enrollment No: 24UG035720 Page No:


Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1

3.3
Input:-

Output:-

Enrollment No: 24UG035720 Page No:


Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1

3.4

Input:-

Output:-

Enrollment No: 24UG035720 Page No:


Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1

3.5

Input:-

Ouput:-

Enrollment No: 24UG035720 Page No:


Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1

3.6

Input:-

Ouput:-

Enrollment No: 24UG035720 Page No:


Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1

Enrollment No: 24UG035720 Page No:


Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1

Enrollment No: 24UG035720 Page No:


Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1

Practical 4
While & Do-While Statements

A while loop in C is a pre-tested loop that executes a section of code while a condition is true. The loop
evaluates the condition before each iteration. If the condition is true, the loop body executes. The loop
repeats until the condition is false, at which point the loop terminates.

For example, if i is initialized to 1 before the loop, and the condition is i <= 10, the loop will execute
until i becomes 10.

While loops can be used to prompt a user to enter information indefinitely. For example, you can use a
while loop to check if a user has typed in a name.

A do while loop in C is a structured loop that executes a code block at least once and repeats it while a
condition is true. The loop body statement is any valid C statement or block, and the condition expression
is evaluated at the end of each loop pass. If the condition expression is false, the loop exits.

A while loop is similar to a do while loop, but it tests the condition expression before each loop pass. This
means that a while loop may execute its loop body statement zero times.

You can use the break command to terminate a do while loop from any point other than the logical end.

Enrollment No: 24UG035720 Page No:


Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1

Practical 5

For Loop Programs

The for loop in C language is used to iterate the statements or a part of the program several times. It is
frequently used to traverse the data structures like the array and linked list.

How for loop works:

 The initialization statement is executed only once.

 Then, the test expression is evaluated. If the test expression is evaluated to false, the for loop
is terminated.
 However, if the test expression is evaluated to true, statements inside the body of the for loop
are executed, and the update expression is updated.
 Again the test expression is evaluated.

This process goes on until the test expression is false. When the test expression is false, the loop
terminates.

Enrollment No: 24UG035720 Page No:

You might also like