M.pranathi Cdst1
M.pranathi Cdst1
M.pranathi Cdst1
BACHELOR OF TECHNOLOGY
Laboratory Manual
Enrollment no:23UG032890
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
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.
2|P ag e
Enrollment no:23UG032890
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
Instructions to students
3|P ag e
Enrollment no:23UG032890
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
CERTIFICATE
Head of Department:...........................................
4|P ag e
Enrollment no:23UG032890
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
INDEX
Date
Sr. Date of
of Marks
No Experiment Title Page Perfor Sign
Assess out 0f 10
. No. mance
ment
5|P ag e
Enrollment no:23UG032890
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
6|P ag e
Enrollment no:23UG032890
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
7|P ag e
Enrollment no:23UG032890
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
Practical 1
1. AIM: Installation C IDE, Basic Structure of C program. Format Specifiers,
Escape Character. Run time input/Output Programs.
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.
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:
8|P a g e
Enrollment no:23UG032890
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:
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:
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.
9|P a g e
Enrollment no:23UG032890
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
Example:
%c For b type.
%i Unsigned integer
%lf Double
%o Octal representation
10 | P a g e
Enrollment no:23UG032890
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
Sequence Name Description
\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.
11 | P a g e
Enrollment no:23UG032890
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
Escape
Sequence Name Description
Hexadecimal
\xhh It represents the hexadecimal number.
Number
Example:
#include <stdio.h>
int main() {
inside q// printf() displays the string uotation
printf("Hello, World!");
return 0;
}
12 | P a g e
Enrollment no:23UG032890
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
Practical 2
1. Write a c program to calculate Area of Rectangle , Perimeter of a
Rectangle and Diagonal of a Rectangle.
#include <stdio.h>
int main() {
int length, breadth, area, perimeter, diagonal;
return 0;
}
13 | P a g e
Enrollment no:23UG032890
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
#include<stdio.h>
#include<math.h>
int main()
float a,area,perimeter,diagonal;
scanf("%f",&a);
area=a*a;
perimeter=4*a;
diagonal=sqrt(2*a);
return 0;
14 | P a g e
Enrollment no:23UG032890
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
int main() {
return 0;
15 | P a g e
Enrollment no:23UG032890
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
Practical-3
1. The total distance traveled by vehicle in t seconds is given by distance s =
ut+1/2at? where u and a are the initial velocity (m/sec.) and acceleration
(m/sec?). Write a C program to find the distance traveled at regular intervals of
time given the values of u and a The program should provide the flexibility to
the user to select his own time intervals and repeat the calculations for different
values of u and a ?
#include<stdio.h>
Int main()
int a,u,t,t1,t2,i;
float s;
clrscr();
scanf("%d%d%d%d%d",&a,&u,&t,&t1,&t2);
for(i=t1;i<=t2;i=i+t)
s=(u*i)+(0.5*a*i*i);
return 0;
Output:
16 | P a g e
Enrollment no:23UG032890
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
17 | P a g e
Enrollment no:23UG032890
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 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;
18 | P a g e
Enrollment no:23UG032890
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
case '/':
printf("Result is: %d",(a/b));
break;
default:
printf("Invalid operand!");
}
Return 0;
}
Output:
19 | P a g e
Enrollment no:23UG032890
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
Practical-4
1. Write a C program to find the sum of individual digits of a positive integer.
#include<stdio.h>
#include<math.h>
int main()
int n,sum=0;
scanf("%d",&n);
while(n>0)
sum=sum+n%10;
n=n/10;
20 | P a g e
Enrollment no:23UG032890
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
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.
#include <stdio.h>
int main() {
int i, n;
int t1 = 0, t2 = 1;
scanf("%d", &n);
t1 = t2;
t2 = nextTerm;
nextTerm = t1 + t2;
return 0;
21 | P a g e
Enrollment no:23UG032890
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
#include <stdio.h>
int main() {
int i,num,n,count;
scanf(“%d”,&n);
for(num=1;num<=n;num++)
count=0;
for(i=2;i<=num/2;i++)
{ if(num%i= =0)
{ count++;
break;
if(count= = 0&&num!=1)
printf(“%d“,num);
22 | P a g e
Enrollment no:23UG032890
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
Practical-5
1. Write a C program to calculate the following Sum: Sum=1-x^2/2! +x^4/4!-
x^6/6!+x^8/8!-x^10/10!.
#include <stdio.h>
#include <math.h>
int main()
int counter,f_coun;
float sum=0,x,power,fact;
scanf("%f",&x);
fact=1;
fact *= f_coun;
sum=sum+(pow(-1,counter)*(pow(x,power)/fact));
printf("SUM : %f",sum);
23 | P a g e
Enrollment no:23UG032890
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
# include<math.h>
int main () {
float a,b,c,r1,r2,d;
d= b*b - 4*a*c;
if (d>0) {
else if (d==0) {
r1 = -b/(2*a);
r2 = -b/(2*a);
else
return 0;
24 | P a g e
Enrollment no:23UG032890
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
Practical 6
Write C programs that use both recursive and non-recursive functions.
1. To find the factorial of a given integer.
#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);
return 0;
25 | P a g e
Enrollment no:23UG032890
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
non-recursive functions:
#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;
26 | P a g e
Enrollment no:23UG032890
Faculty of Engineering & Technology
303105104 – Computational Thinking for Structured
Design-1
int main ()
int n1,n2;
return 0;
if(n2 !=0)
return hcf(n2,n1%n2);
else
return n1;
27 | P a g e
Enrollment no:23UG032890