M.sravan Kumar CTSD
M.sravan Kumar CTSD
BACHELOR OF TECHNOLOGY
Laboratory Manual
Enrollment no:23UG0321974
2|Page
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
PREFACE
3|Page
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
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.
4|Page
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
5|Page
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
Instructions to students
6|Page
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
7|Page
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
8|Page
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
CERTIFICATE
9|Page
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
Head of Department:...........................................
10 | P a g e
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured Design-1
INDEX
Date of Date
Sr. Perfor of Marks
No Experiment Title Page mance Assess out 0f 10 Sign
. No. ment
5 | P a g e Enrollment
no:23UG032165
6|Page
Enrollment no:23UG032165
7|Page
Enrollment no:23UG03
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
15
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
Practical 1
16 | P a g e
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
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:
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:
|Page
17
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
#include<stdio.h>
18 | P a g e
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
#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:
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.
|Page
19
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
%c For b type.
%i Unsigned integer
%lf Double
%o Octal representation
20 | P a g e
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
Example:
21
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
22 | P a g e
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
%p Pointer
%s String
%u Unsigned int
%x or %X Hexadecimal representation
%n Prints nothing
%% Prints % character
Escape
Name Description
Sequence
\f Form Feed It is used to move the cursor to the start of the next 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.
\t Horizontal Tab It inserts some whitespace to the left of the cursor and
moves the cursor accordingly.
23 |
Page
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
24 | P a g e
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
26 | P a g e
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
Escape
Name Description
Sequence
27 | P a g e
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
Example:
28 | P a g e
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
29 | P a g e
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
Practical 2
30 | P a g e
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
return 0;
}
31 | P a g e
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
32 | P a g e
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
Diagonal of a square.
#include<stdio.h> #include<math.h>
int main()
=%0.2f\n",diagonal); return 0;
34 | P a g e
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
printf("Enter the radius and height of the cylinder: "); scanf("%lf%lf", &radius,
&height);
return 0;
36 | P a g e
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
Practical-3
37 | P a g e
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
#include<stdio.h>
Int main()
s; clrscr();
for(i=t1;i<=t2;i=i+t)
s=(u*i)+(0.5*a*i*i);
}
return 0;
Output:
38 | P a g e
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
39 | P a g e
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
40 | P a g e
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
41 | P a g e
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
2. Write a C program, which takes two integer operands and one operator from the
42 | P a g e
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
user, performs the operation and then prints the result. (Consider the operators and
use Switch Statement)?
//C program which takes two integer operands and one operator from the user, performs the operation and
then prints the result
#include<stdio.h>
#include<math.h> int
main()
{
int a, b; char op; printf("Enter two integer values:
");
scanf("%d%d",&a,&b);
printf("Enter a operand + or - or * or / or %: ");
scanf("%c",&op); switch(op)
{
case '+': printf("Result is: %d",(a+b)); break;
case '-':
printf("Result is: %d",(a-b)); break;
case '*': printf("Result is: %d",(a*b)); break;
43 | P a g e
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
44 | P a g e
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
45 | P a g e
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
default:
printf("Invalid operand!");
}
Return 0;
}
Output:
46 | P a g e
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
47 | P a g e
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
48 | P a g e
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
#include<stdio.h>
#include<math.h> int
main()
int n,sum=0;
while(n>0)
sum=sum+n%10; n=n/10;
49 | P a g e
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
2. A Fibonacci sequence is defined as follows: the first and second terms in the
50 | P a g e
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
sequences are 0 and 1. Subsequent terms are found by adding the preceding two
terms in the sequence. Write a C program to generate the first n terms of the
sequence.
int i, n;
int t1 = 0, t2 = 1;
int nextTerm = t1 + t2;
}
return 0;
51 | P a g e
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
3. Write a C program to generate all the prime numbers between 1 and n, where n
52 |
Page
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
range”);
scanf(“%d”,&n);
for(num=1;num<=n;num++)
count=0; for(i=2;i<=num/2;i++)
{ if(num%i= =0)
{ count++;
break;
53 |
Page
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
Practical-5
54 |
Page
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
int counter,f_coun;
float sum=0,x,power,fact;
printf("\tEQUATION SERIES : 1- X^2/2! + X^4/4! - X^6/6! + X^8/8! - X^10/10!");
fact=1;
fact *= f_coun;
sum=sum+(pow(-1,counter)*(pow(x,power)/fact));
printf("SUM : %f",sum);
55 |
Page
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
56 |
Page
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
# include<stdio.h> #
float a,b,c,r1,r2,d;
if (d>0) {
(2*a);
r2 = -b/(2*a);
}
else
return 0;
57 |
Page
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
Practical 6
58 |
Page
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
#include<stdio.h>
int fact(int n)
{ if(n==0) return 1;
else
return n*fact(n-1);
}
void main()
{
int n,f;
scanf("%d",&n); f=fact(n);
59 |
Page
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
non-recursive functions:
60 |
Page
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
#include<stdio.h> int
fact(int n)
int f=1,i;
if((n==0)||(n==1))
return(1); else
for(i=1;i<=n;i++) f=f*i;
return(f);
void main()
int n;
scanf("%d",&n); printf("factoria of
number%d",fact(n)); return 0;
61 |
Page
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
62 |
Page
Enrollment no:23UG031974
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
int n1,n2;
",n1,n2,hcf(n1,n2));
return 0; }
if(n2 !=0)
return hcf(n2,n1%n2);
63 |
Page
Enrollment no:23UG031974