CTSD Manual
CTSD Manual
BACHELOR OF TECHNOLOGY
Laboratory Manual
PREFACE
It gives us immense pleasure to present the first edition of Computational Thinking for
Structure Design -1for the B.Tech. 1st year studentsfor PARUL UNIVERSITY.
The Fundamental of Programming theory and laboratory courses at PARUL
UNIVERSITY,WAGHODIA,VADODARAaredesignedinsuchawaythatstudentsdevelopthe
basic understanding of the subject in the theory classes and thentrytheirhandsonthecomputer
learnt during the theoretical sessions.
Thisbookisemphaticallynotfocusedon“thesyntaxofC”.Understandingthefundamental
ideals, principals, and techniques is the essence of a goodprogrammer.Onlywell-designedcode
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.
Weacknowledgetheauthorsandpublishersofallthebookswhichwehaveconsultedwhile
developingthisPracticalbook.HopefullythisComputationalThinkingforStructureDesign-1will
serve the purpose for which it has been developed.
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
Instructions to students
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
CERTIFICATE
Mr./Ms………..................................................................................................... with
Head of Department:...........................................
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
INDEX
Date
r.
S ate of
D arks
M
of
No Experiment Title Page Perfor out 0f Sign
sses
A
. No. mance 10
sment
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
1 . Write a C program to find the sum of
individual digits of a positive integer.
2. A Fibonacci sequence is defined as follows:
the first and second terms in the sequences are
0 and 1. Subsequent terms are
4 found by adding the preceding two terms in the
sequence. Write a C program to generate the
first n terms of the sequence.
3. Write a C program to generate all the prime
numbers between 1 and n, where n is a value
supplied by the user.
1. Write a C program to calculate the following
Sum: Sum=1-x^2/2!
5 +x^4/4!-x^6/6!+x^8/8!-x^10/10!.
2. Write a C program to find the roots of a
quadratic equation.
Write C programs that use both recursive and
non-recursive functions.
6 1. To find the factorial of a given integer.
2. To find the GCD (greatest common divisor)
of two given integers.
1. Write a C program to find the largest integer
in a list of integers,
7 2. Write a C program that uses functions to
perform the following:
1. Addition of Two Matrices
2. Multiplication of Two Matrices
1. Write a C program that uses functions to
perform the following operation;
1. To insert a sub-string into a given main
8 string from a given position.
2. To delete n Characters from a given position
in a given string,
2. Write a C program to determine if the given
string is a palindrome or not.
1. Write a C program that displays the
position or index in the string S where the
9 string T begins, or -1 if S doesnt contain
T.
2. Write a C program to count the lines, words
and characters in a given text.
1. Write a C program to generate Pascal's
10 triangle.
2. Write a C program to construct a pyramid of
numbers.
Write a C program to read in two numbers, x
11 and n, and then compute the sum of this
geometric progression:
1+x+x^2+x^3+... x^n.
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
or example: if n is 3 and x is 5, then the
F
program computes 1+5+25+125.Print x, n, the
sum.
Perform error checking. For example, the
formula does not make sense for negative
exponents if n is less than 0. Have
your program print an error - message if n<0,
then go back and read in the next pair of
numbers without computing the sum.
Are any values of x also illegal? If so, test for
them too.
1. 2's complement of a number is obtained by
scanning it from right to left and
complementing all the bits after the first
appearance of a 1. Thus 2s complement of
12 11100 is 00100. Write a C program to find the
2's complement of a binary
number.
2. Write a C program to convert a Roman
numeral to its decimal Equivalent.
1. Write a c program on Given an unsorted
array arr[] of size N. Rotate the array to the left
(counter-clockwise direction) by D
steps, where D is a positive integer.
2. Write a c Program on given two sorted
arrays arr1 and arr2 of size N and M
respectively and an element K. The task is to
find the element that would be at the kth
13 position of the final sorted array.Explanation:
Input :
Array 1 - 1 4 2 3 5
Array 2 - 7 8 6
k = 5
Output : 5
Because The final sorted array would be -1, 2,
3, 4, 5, 6, 7, 8, The 5th element of this array is
6.
1. Write a c program to take multiline string
input and print individual string length .
14 2. Write a c program to reverse the individual
word of a given string Explanation:input :
Welcome To Bytexl output: emocleW
oT lxetyB.
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
Practical 1
1. I nstallation C IDE, Basic Structure of C program. Format Specifiers, Escape Character.
Run time input/Output Programs.
he basic structure of a C program is divided into 6 parts which makes it easy to read, modify,
T
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 . ocumentation
D
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:
# include<stdio.h>
#include<math.h>
3. Definition
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
reprocessors are the programs that process our source code before the process of compilation.
P
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:
v oid 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:
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
ist of Format Specifiers in C
L
The below table contains the most commonly used format specifiers in C
%lf Double
%p Pointer
%s String
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
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.
\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.
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
Escape
Sequence Name Description
exadecimal
H
\xhh It represents the hexadecimal number.
Number
xample:
E
#include <stdio.h>
int main() {
// printf() displays the string inside quotation
printf("Hello, World!");
return 0;
}
Enrollment No:23UG033506
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.
Input:
#include <stdio.h>
#include <math.h>
int main()
{
scanf("%f", &length);
scanf("%f", &breadth);
return 0;
}
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
Out put:
Input:
#include <stdio.h>
#include <math.h>
int main()
{
float side,perimeter,diagonal,area;
scanf("%f", &side);
area = side*side;
perimeter = 4*side;
diagonal = sqrt(2)*side;
return 0;
}
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
Out put:
3. Write a c program to calculate total area of Cylinder and volume of a cylinder.
Input:
#include <stdio.h>
#include <math.h>
int main()
{
scanf("%f", &radius);
scanf("%f", &height);
return 0;
}
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
Out put:
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.
Input:
#include<stdio.h>
#include<math.h
{
int n, sec;
float d, u, a;
scanf("%d", &sec);
scanf("%f", &u);
scanf("%f", &a);
}
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
Out put:
. Write a C program, which takes two integer operands and one operator from the
2
user, performs the operation and then prints the result. (Consider the operators and
use Switch Statement)
Input:
#include <stdio.h>
int main()
{
int a, b, c;
char ch;
switch (ch)
{
case '+':
c = a + b;
break;
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
case '-':
c = a - b;
break;
case '*':
c = a * b;
break;
case '%':
c = a % b;
break;
default:
printf("Invalid operator");
break;
}
return 0;
Out put:
Enrollment No:23UG033506
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.
Input:
#include <stdio.h>
int main() {
scanf("%d", &num);
}
}
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
return 0; // Exit successfully
}
Out put:
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
Input:
#include <stdio.h>
int main() {
int n, i;
scanf("%d", &n);
if (n <= 0) {
}
if (n >= 1) {
}
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
if (n >= 2) {
}
first = second;
second = next;
}
printf("\n");
}
Out put:
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
Input:
#include <stdio.h>
#include <stdbool.h>
return false;
}
if (num % i == 0) {
return false;
}
}
return true;
}
int main() {
int n;
scanf("%d", &n);
if (n < 2) {
return 1;
}
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
if (is_prime(i)) {
}
}
printf("\n");
return 0;
}
Out put:
Practical 5
#include <stdio.h>
#include <math.h>
int factorial(int n) {
if (n == 0) {
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
return 1;
} else {
}
}
int main() {
int n;
scanf("%lf", &x);
scanf("%d", &n);
if (n % 2 != 0) {
return 1;
}
sum += term;
}
return 0;
}
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
Out put:
#include <stdio.h>
#include <math.h>
int main() {
double a, b, c;
discriminant = b * b - 4 * a * c;
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
printf("Root 2 = %.2lf\n", root2);
} else if (discriminant == 0) {
root1 = -b / (2 * a);
} else {
}
return 0;
}
Out put:
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
Practical 6
Recursion
Input:
#include <stdio.h>
if (n == 0) {
return 1;
} else {
}
}
int main() {
int num;
scanf("%d", &num);
}
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
unsigned long long int result = factorial_recursive(num);
return 0;
}
Out put:
Non- recursion
Input:
#include <stdio.h>
result *= i;
}
return result;
}
int main() {
int num;
scanf("%d", &num);
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
}
return 0;
}
Out put:
2. To find the GCD (greatest common divisor) of two given integers.
Recursion
Input:
// Online C compiler to run C program online
#include <stdio.h>
if (b == 0) {
return a;
} else {
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
}
}
int main() {
scanf("%d", &num1);
scanf("%d", &num2);
}
return 0;
}
Out put:
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
Non- recursion
Input:
#include <stdio.h>
while (b != 0) {
b = a % b;
a = temp;
}
return a;
}
int main() {
scanf("%d", &num1);
scanf("%d", &num2);
}
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
return 0;
}
Out put:
Practical 7
#include <stdio.h>
int main() {
scanf("%d", &n);
if (n <= 0) {
}
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
// Ask the user to enter the first integer
scanf("%d", &max);
scanf("%d", &num);
// Check if the current number is greater than the current maximum
max = num;
}
}
return 0;
}
Out put:
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
#include <stdio.h>
scanf("%d", &matrix[i][j]);
}
}
}
oid addMatrices(int rows, int cols, int matrix1[][cols], int matrix2[][cols], int
v
result[][cols]) {
}
}
}
printf("%d\t", matrix[i][j]);
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
}
printf("\n");
}
}
int main() {
scanf("%d", &rows);
scanf("%d", &cols);
int matrix1[rows][cols];
int matrix2[rows][cols];
int result[rows][cols];
return 0;
}
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
Out put:
Matrix-1
Matrix-2
Input:
#include <stdio.h>
scanf("%d", &matrix[i][j]);
}
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
}
}
oid multiplyMatrices(int rows1, int cols1, int matrix1[][cols1], int rows2, int cols2, int
v
matrix2[][cols2], int result[][cols2]) {
result[i][j] = 0;
}
}
}
}
printf("%d\t", matrix[i][j]);
}
printf("\n");
}
}
int main() {
scanf("%d", &rows1);
scanf("%d", &rows2);
scanf("%d", &cols2);
}
int matrix1[rows1][cols1];
int matrix2[rows2][cols2];
int result[rows1][cols2];
return 0;
}
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
Out put:
Matrix-1 (2x3):
Matrix-2 (3x2):
Practical 8
1. Write a C program that uses functions to perform the following operation;
1. To insert a sub-string into a given main string from a given position.
Input:
// Online C compiler to run C program online
#include <stdio.h>
#include <string.h>
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
if (position < 0 || position > mainLen) {
return;
}
return;
}
}
mainString[position + i] = subString[i];
}
}
int main() {
char mainString[255];
char subString[255];
int position;
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
printf("Enter the sub-string to insert: ");
scanf("%d", &position);
return 0;
}
Out put:
#include <stdio.h>
#include <string.h>
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
return;
}
if (n <= 0) {
return;
}
str[position] = '\0'; // If deletion extends beyond the string length, truncate the string.
} else {
}
}
}
int main() {
char inputString[255];
scanf("%d", &position);
scanf("%d", &n);
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
return 0;
}
Out put:
Input:
// Online C compiler to run C program online
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
return false;
}
}
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
return true;
}
int main() {
char inputString[255];
if (isPalindrome(inputString)) {
} else {
}
return 0;
}
Out put:
owever, if you enter a non-palindromic string, such as "hello," the program will
H
output:
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
Practical 9
1. Write a C program that displays the position or index in the string S where the string T
begins, or -1 if S doesn’t contain T.
Input:
// Online C compiler to run C program online
#include <stdio.h>
#include <string.h>
int j;
break;
}
}
if (j == T_len) {
}
}
}
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
int main() {
char stringS[255];
char stringT[255];
} else {
}
return 0;
}
Out put:
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
2.Write a C program to count the lines, words and characters in a given text.
Input:
// Online C compiler to run C program online
#include <stdio.h>
#include <stdio.h>
#include <ctype.h>
int main() {
char text[1000];
int lines = 0, words = 0, characters = 0;
char prevChar = ' ';
printf("Enter the text (Ctrl+D to end input on Unix/Linux, Ctrl+Z on Windows):\n");
// Read the text until EOF (End of File) is encountered
while (fgets(text, sizeof(text), stdin) != NULL) {
lines++;
for (int i = 0; text[i] != '\0'; i++) {
characters++;
if (isspace(text[i])) {
if (!isspace(prevChar)) {
words++;
}
}
prevChar = text[i];
}
}
printf("\nLines: %d\nWords: %d\nCharacters: %d\n", lines, words, characters);
return 0;
}
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
Out put:
Practical 10
#include <stdio.h>
if (k == 0 || k == n) {
return 1;
} else {
}
}
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
int main() {
int numRows;
scanf("%d", &numRows);
printf(" ");
}
}
printf("\n");
}
return 0;
}
Out put:
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
#include <stdio.h>
int main() {
scanf("%d", &rows);
printf(" ");
}
}
}
printf("\n");
}
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
return 0;
}
Out put:
Practical 11
1 . WriteaCprogramtoreadintwonumbers,xandn,andthencomputethesumofthis
geometric progression:
1+x+x^2+x^3+... x^n.
For example: if n is 3 and x is 5, then the program computes 1+5+25+125.Print x, n, the sum.
erform error checking. For example, the formula does not make sense for negative
P
exponents – if n is less than 0. Have
y our program print an error - message if n<0, then go back and read in the next pair of
numbers without computing the sum.
Are any values of x also illegal? If so, test for them too.
Input:
// Online C compiler to run C program online
#include <stdio.h>
#include <math.h>
int main() {
int n;
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
while (1) {
}
if (n < 0) {
}
if (x == 1.0) {
}
printf("Warning: The series may not converge for x outside the range [-1, 1].\n");
}
}
}
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
return 0;
}
Out put:
Practical 12
1 . 2's complement of a number is obtained by scanning it from right to left and
complementingallthebitsafterthefirstappearanceofa1.Thus2’scomplementof11100is
00100. Write a C program to find the 2's complement of a binary number.
Input:
// Online C compiler to run C program online
#include <stdio.h>
#include <string.h>
int main() {
char binaryNumber[100];
scanf("%s", binaryNumber);
length = strlen(binaryNumber);
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
if (binaryNumber[i] == '1') {
break;
}
}
if (i == -1) {
return 0;
}
}
return 0;
}
Out put:
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
return decimalNum;
}
int main() {
char romanNumeral[20];
printf("Enter a Roman numeral: ");
scanf("%s", romanNumeral);
int result = romanToDecimal(romanNumeral);
if (result != -1) {
printf("Decimal equivalent: %d\n", result);
}
return 0;
}
Out put:
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
Practical 13
1 . WriteacprogramonGivenanunsortedarrayarr[]ofsizeN.Rotatethearraytotheleft
(counter-clockwise direction) by D steps, where D is a positive integer.
Input:
// Online C compiler to run C program online
#include <stdio.h>
if (D <= 0) {
return;
}
int temp[D];
temp[i] = arr[i];
}
}
// Copy the rotated elements from the temporary array to the end of the original array
arr[i] = temp[j];
}
}
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
int main() {
int N, D;
scanf("%d", &N);
if (N <= 0) {
return 1;
}
int arr[N];
scanf("%d", &arr[i]);
}
scanf("%d", &D);
rotateLeftByD(arr, N, D);
printf("Rotated array:\n");
}
printf("\n");
return 0;
}
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
Out put:
. Write a c Program on given two sorted arrays arr1 and arr2 of size N and M
2
respectivelyandanelementK.Thetaskistofindtheelementthatwouldbeatthekth
position of the final sorted array.Explanation:
Input :
Array 1 - 1 4 2 3 5
Array 2 - 7 8 6
k = 5
Output : 5
Input:
#include <stdio.h>
int i = 0, j = 0;
} else {
mergedArr[mergedSize++] = arr2[j++];
}
}
while (i < N) {
mergedArr[mergedSize++] = arr1[i++];
}
while (j < M) {
mergedArr[mergedSize++] = arr2[j++];
}
}
}
int main() {
int N, M, k;
scanf("%d", &N);
int arr1[N];
scanf("%d", &arr1[i]);
}
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
printf("Enter the size of the second array (M): ");
scanf("%d", &M);
int arr2[M];
scanf("%d", &arr2[i]);
}
scanf("%d", &k);
printf("The %dth element of the final sorted array is: %d\n", k, result);
} else {
}
return 0;
}
Out put:
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
Practical 14
1.Write a c program to take multiline string input and print individual string length.
Input:
#include <stdio.h>
#include <string.h>
int main() {
char inputString[1000];
while (1) {
char line[1000];
break;
}
totalLength += lineLength;
}
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
return 0;
}
Out put:
. Write a c program to reverse the individual word of a given string
2
Explanation:input : Welcome To Bytexl output: emocleW oT lxetyB.
Input:
#include <stdio.h>
#include <string.h>
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
for (int j = i - 1; j >= start; j--) {
printf("%c", str[j]);
}
}
start = i + 1;
}
}
}
int main() {
char inputString[1000];
reverseWords(inputString);
printf("\n");
return 0;
}
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
Out put:
Enrollment No:23UG033506
Faculty of Engineering & Technology
303105104 - Computational Thinking for Structured Design-1
Enrollment No:23UG033506