KEMBAR78
Department of Computer Science and Engineering | PDF | String (Computer Science) | Numbers
0% found this document useful (0 votes)
15 views47 pages

Department of Computer Science and Engineering

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)
15 views47 pages

Department of Computer Science and Engineering

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/ 47

DEPARTMENT OF COMPUTER SCIENCE AND

ENGINEERING
PROGRAMMING FUNDAMENTALS

CO 101

LAB FILE

SUBMITTED TO SUBMITTED BY:


MS. ANUKRITI KAUSHAL MUKUL RAJ KASTOR
2K22/B6/68
CIVIL ENGINEERING

1 MUKUL RAJ
KASTOR 2K22/B6/68
INDEX
S. Objective Date Sign
No.
1. Write a Program to find the sum and 13/12/2022
average of two numbers.

2. Write a Program to find the largest 13/12/2022


number.

3. Write a Program to find Simple 13/12/2022


Interest.

4. Write a Program to print the 13/12/2022


following pattern.(triangle of stars)

5. Write a Program to find whether the 13/12/2022


entered number is prime.

6. Write a Program to find the sum of a 13/12/2022


5-digit number.

7. Write a Program to reverse a 5-digit 13/12/2022


number.

8. Write a Program to convert decimal 13/12/2022


to binary and vice versa.

9. Write a Program to implement the 13/12/2022


switch case statement.

10. Write a Program to generate the 13/12/2022


Fibonacci sequence.

11. Write a Program to find the 13/12/2022


exponential function.

12. Write a Program to search a number 13/12/2022


from an array using linear search.

13. Write a Program to search a number 13/12/2022


from an array using binary search

14. Write a program to find the length of 9/01/2023


the string with and without using
strlen function.

15. Write a Program to count the 9/01/2023


number of vowels in a given string.

16. Write a Program to check if a given 9/01/2023


string is a palindrome or not.

2 MUKUL RAJ
KASTOR 2K22/B6/68
17. Write a Program to string 9/01/2023
concatenation.

18. Write a Program to string 9/01/2023


comparison.

19. Write a Program to string reverse. 9/01/2023

20. Write a Program to convert a string 9/01/2023


from lower case to upper case and
vice versa

21. Program to sort an array using 23/01/2023


Bubble sort

22. Program to sort an array using 23/01/2023


selection sort.

23. Program to sort an array using 23/01/2023


insertion sort

24. Program for the addition of two 3 x 3 23/01/2023


matrices.

25. Program to multiply two 3 x 3 23/01/2023


matrices

26. Program to swap two numbers using 23/01/2023


pointers

27. Program to generate the employee 23/01/2023


details using a structure.

28. Program to find the area and 23/01/2023


perimeter of a circle, rectangle,
square and triangle using Functions.

29. Program which copies one file 6/02/2023


contents to another file.

30. Program to read a file and after 6/02/2023


converting all lower case to upper
case letters write it to another file.

31. Program to find the size of a given 6/02/2023


file.

3 MUKUL RAJ
KASTOR 2K22/B6/68
EXPERIMENT-1
AIM: Write a Program to find the sum and average of two
numbers.
THEORY: We calculate average by adding two numbers and
divide by 2
ALGORITHM: Step1: input 2 numbers a,b .
Step 2: average=(a+b)/2.
Step 3: display average.
INPUT

OUTPUT

4 MUKUL RAJ
KASTOR 2K22/B6/68
EXPERIMENT-2
AIM: Write a Program to find the largest number.
THEORY: Checking the greatest of three number
ALGORITHM: Step 1: input n numbers .
Step 2: assuming a[0] is greatest
a[i]>greatest;
greatest=a[i]
Step 3: Dsiplay the greatest
INPUT

OUTPUT

5 MUKUL RAJ
KASTOR 2K22/B6/68
EXPERIMENT-3
AIM: Write a Program to find Simple Interest.
THEORY: simple interest=principal amount*rate*time/100
ALGORITHM: Step1: input principal amount,rate,time.
Step2: simple interest=principal amount*rate*time/100.
Step 3: Display simple interest.
INPUT

OUTPUT

6 MUKUL RAJ
KASTOR 2K22/B6/68
EXPERIMENT-4
AIM: Write a Program to print the following pattern.
(triangle of stars)
THEORY: We need to understand the concept of “for loop”.
ALGORITHM: Step 1: input the number of rows.
Step 2: Iterate the loops till the number of rows.
Step 3: Display the 1 star in row.
Step 4: increase till the number of rows.
INPUT

7 MUKUL RAJ
KASTOR 2K22/B6/68
OUTPUT

EXPERIMENT-5
AIM: Write a Program to find whether the entered number
is prime.
THEORY: Prime numbers are divisible by 1 and itself.
ALGORITHM: STEP 1: enter the number.
Step2: iterate the loop till the square root of number.
Step 3: divide the number till the loop iterate.
Step 4: if it is divisible by more than 2 numbers it is a prime
number.
8 MUKUL RAJ
KASTOR 2K22/B6/68
INPUT

OUTPUT

EXPERIMENT-6
AIM: Write a Program to find the sum of a 5-digit number.
THEORY: number is 12345 sum would be 15 .
ALGORITHM: Step 1: input a number.
Step2: iterate a loop till 5.
Step3: find the remainder and add that to sum.
Step4: divide number by 10.
Step5: display sum.
INPUT
9 MUKUL RAJ
KASTOR 2K22/B6/68
OUTPUT

EXPERIMENT-7
AIM: Write a Program to reverse a 5-digit number.
THEORY: let a number be 12345 its reverse number is 54321
ALGORITHM: Step 1: input a number.
Step2: iterate a loop till number is not equal to 0.
Step3: find remainder than reverse=reverse*10+remainder
Step4: divide number by 10.
Step5: display reversed number.
INPUT
10 MUKUL
RAJ KASTOR 2K22/B6/68
OUTPUT

EXPERIMENT-8
AIM: Write a Program to convert decimal to binary and vice
versa.
THEORY: decimal numbers are from 0 to 9 and binary
numbers are 0 and 1.
ALGORITHM: Step 1: Divide the number by 2 and find the
remainder, then store the remainder in an array.
Step 2: Divide the number by 2.

11 MUKUL
RAJ KASTOR 2K22/B6/68
Step 3: Repeat the above two steps until the number is
greater than zero.
Step 4: Print the array in reverse order to get the binary
representation of the number.
INPUT

OUTPUT

EXPERIMENT-9
AIM: Write a Program to implement the switch case
statement.
THEORY: The switch statement is used to test the equality
of a variable against several values specified in the test
cases.
FLOWCHART:

12 MUKUL
RAJ KASTOR 2K22/B6/68
INPUT

OUTPUT

EXPERIMENT-10
AIM: Write a Program to generate the Fibonacci sequence.
THEORY: The sequence follows the rule that each number is
equal to the sum of the preceding two numbers.
FLOWCHART:

13 MUKUL
RAJ KASTOR 2K22/B6/68
INPUT

OUTPUT

EXPERIMENT-11
AIM: Write a Program to find the exponential function.
THEORY: An exponential function is defined by the
formula f(x) = ax

14 MUKUL
RAJ KASTOR 2K22/B6/68
ALGORITHM: Step 1: we raised e to the power any value
using exp(n).
Step 2: display the e to the power any value.
INPUT

OUTPUT

EXPERIMENT-12
AIM: Write a Program to search a number from an array
using linear search.
THEORY: It examines each element until it finds a match,
starting at the beginning of the data set, until the end.
15 MUKUL
RAJ KASTOR 2K22/B6/68
ALGORITHM: Step 1: input a list of number.
Step2: start iterating the elements of list till the end.
Step3: check whether the number is to find at which at
location.
INPUT

OUTPUT

EXPERIMENT-13
AIM: Write a Program to search a number from an array
using binary search
THEORY: Binary search compares the target value to the
middle element of the array.
16 MUKUL
RAJ KASTOR 2K22/B6/68
ALGORITHM: Step 1: input a list of number.
Step2: start iterating the elements of list till the end.
Step3: check whether the number at the middle position is
same which to find.
Step 4: if the number is small than middle number than
start searching on left and vica versa.
INPUT

OUTPUT

EXPERIMENT-14
AIM: Write a program to find the length of the string with
and without using strlen function.
THEORY: let the string be “hello” its length is “5”.
17 MUKUL
RAJ KASTOR 2K22/B6/68
ALGORITHM: Step 1: input a string.
Step 2: iterate the loop till end of character.
Step 3: increment the count by 1.
Step 4: display the count.
INPUT

OUTPUT

EXPERIMENT-15
AIM: Write a Program to count the number of vowels in a
given string.
THEORY: vowels are a,e,i,o,u.
18 MUKUL
RAJ KASTOR 2K22/B6/68
ALGORITHM: Step 1: enter a string.
Step 2: iterate the loop till the length of string.
Step 3: check the each alphabet is equal to the vowel.
Step 4: display the total sum of vowels.
INPUT

OUTPUT

EXPERIMENT-16
AIM: Write a Program to check if a given string is a
palindrome or not.
THEORY: PALINDROME string is which is same in reverse
order like mam is equal to mam when it is reversed.
19 MUKUL
RAJ KASTOR 2K22/B6/68
ALGORITHM: Step 1: input a string.
Step 2: copy this string to another string than reversed it.
Step 3: if the reversed string is equal to the inputted string
than string is palindrome.
INPUT

OUTPUT

EXPERIMENT-17
AIM: Write a Program to string concatenation.
THEORY: adding two string like a number “hello” +”world”.
ALGORITHM: Step 1: input 2 string str1,str2.

20 MUKUL
RAJ KASTOR 2K22/B6/68
Step 2: use string function strcat(str1,str2).
Step 3: concatenated string would be displayed.
INPUT

OUTPUT

EXPERIMENT-18
AIM: Write a Program to string comparison.
THEORY: comparing the ascii values of string.
ALGORITHM: Step 1: input 2 string str1,str2.

21 MUKUL
RAJ KASTOR 2K22/B6/68
Step 2: use string function strcmp(str1,str2).
Step 3: both strings are compared.
INPUT

OUTPUT

EXPERIMENT-19
AIM: Write a Program to string reverse.
THEORY: reversing means “hello”  “olleh”.
ALGORITHM: Step 1: input a string str1.
22 MUKUL
RAJ KASTOR 2K22/B6/68
Step 2: use string function strrev(str1).
Step 3: reversed string would be displayed.
INPUT

OUTPUT

EXPERIMENT-20
AIM: Write a Program to convert a string from lower case to
upper case and vice versa.
THEORY: uppercase means converting a string “hello” 
“HELLO” .
23 MUKUL
RAJ KASTOR 2K22/B6/68
ALGORITHM: Step 1: input a string str1.
Step 2: show the menu for performing the uppercase and
lowercase task.
Step 3: use the switch statement.
Step 4: work as per inputted by user for uppercase use string
function strupr(str1) and for lowercase strlwr(str1).
INPUT

OUTPUT

EXPERIMENT-21
AIM: Write a Program to sort an array using Bubble sort.
THEORY: Bubble Sort is the simplest sorting algorithm that
works by repeatedly swapping the adjacent elements if
they are in the wrong order.

24 MUKUL
RAJ KASTOR 2K22/B6/68
ALGORITHM:
 Run a nested for loop to traverse the input array using

two variables i and j, such that 0 ≤ i < n-1 and 0 ≤ j < n-


i-1
 If arr[j] is greater than arr[j+1] then swap these

adjacent elements, else move on


 Print the sorted array

INPUT

OUTPUT

25 MUKUL
RAJ KASTOR 2K22/B6/68
EXPERIMENT-22
26 MUKUL
RAJ KASTOR 2K22/B6/68
AIM: Write a Program sort an array using selection sort.
THEORY: This sorting algorithm, iterates through the array
and finds the smallest number in the array and swaps it with
the first element if it is smaller than the first element.
ALGORITHM: Step 1 − Set min to the first location
Step 2 − Search the minimum element in the array
Step 3 – swap the first location with the minimum value in
the array
Step 4 – assign the second element as min.
Step 5 − Repeat the process until we get a sorted array.
INPUT

OUTPUT

27 MUKUL
RAJ KASTOR 2K22/B6/68
EXPERIMENT-23
28 MUKUL
RAJ KASTOR 2K22/B6/68
AIM: Write a Program to sort an array using insertion sort.
THEORY: Insertion sort is a simple sorting algorithm that
works similar to the way you sort playing cards in your
hands. The array is virtually split into a sorted and an
unsorted part. Values from the unsorted part are picked and
placed at the correct position in the sorted part.
ALGORITHM: To sort an array of size N in ascending order:
 Iterate from arr[1] to arr[N] over the array.

 Compare the current element (key) to its predecessor.

 If the key element is smaller than its predecessor,

compare it to the elements before. Move the greater


elements one position up to make space for the
swapped element.
INPUT

OUTPUT
29 MUKUL
RAJ KASTOR 2K22/B6/68
EXPERIMENT-24

30 MUKUL
RAJ KASTOR 2K22/B6/68
AIM: Write a Program for the addition of two 3 x 3 matrices.
THEORY: In matrice addition the row elements are added to
the same row element and column element to other
column.
ALGORITHM: We first define three matrices A, B, C and read
their respective row and column numbers in variable r and c
1. Read matrices A and B.
2. First, start a loop for getting row elements of A and B
Secondly, inside it again start a loop for column of A
and B
3. Then, we store their corresponding addition by C[i]
[j]=A[i][j] + B[i][j] into C[i][j]
4. At the end of loop, the result of addition is stored in
Matrix C

INPUT
31 MUKUL
RAJ KASTOR 2K22/B6/68
OUTPUT

EXPERIMENT-25
32 MUKUL
RAJ KASTOR 2K22/B6/68
AIM: Write a Program to multiply two 3 x 3 matrices.
THEORY: Two matrices can be multiplied only if the number
of columns in the first matrix equals the number of rows in
the second matrix.
ALGORITHM:

INPUT
33 MUKUL
RAJ KASTOR 2K22/B6/68
OUTPUT

EXPERIMENT-26
34 MUKUL
RAJ KASTOR 2K22/B6/68
AIM: Write a Program to swap two numbers using pointers.
THEORY: We pass the address of variable a and b to
function swap(). Inside function swap() we take a local
variable temp. Since address of variable a and b are passed
to swap() method, we take 2 pointer variables *x and *y.
ALGORITHM: Prompt the user to input two numbers and
store them in variables a and b.
1. Declare three pointers: x, y, and temp.
2. Assign the address of a to x and the address of b to y.
3. Swap the values of a and b by assigning the value of a
to temp, the value of b to a, and the value of temp to
b.
INPUT

OUTPUT

35 MUKUL
RAJ KASTOR 2K22/B6/68
EXPERIMENT-27
36 MUKUL
RAJ KASTOR 2K22/B6/68
AIM: Write a Program to generate the employee details
using a structure.
THEORY: Structure in c is a user-defined data type that
enables us to store the collection of different data types.
ALGORITHM:1. First create a structure employee in which
employee name, employee id, employee salary are stored.
2.Input all the details.
3.Show the employee details.
INPUT

OUTPUT
37 MUKUL
RAJ KASTOR 2K22/B6/68
EXPERIMENT-28

38 MUKUL
RAJ KASTOR 2K22/B6/68
AIM: Write a Program to find the area and perimeter of a
circle, rectangle, square and triangle using Functions.
THEORY: A function is a block of code which only runs when
it is called. You can pass data, known as parameters, into a
function. Functions are used to perform certain actions, and
they are important for reusing code: Define the code once,
and use it many times.
ALGORITHM: 1.Make 4 user defined functions of circle,
rectangle, square and triangle to calculate the perimeter
and area.
2.Now input the required choice from the menu.
3.Now show the result.

INPUT
39 MUKUL
RAJ KASTOR 2K22/B6/68
OUTPUT
40 MUKUL
RAJ KASTOR 2K22/B6/68
EXPERIMENT-29
41 MUKUL
RAJ KASTOR 2K22/B6/68
AIM: Program which copies one file contents to another file.
THEORY: It copies all the data present in the file 1 and copy
all the data into the second file.
ALGORITHM:
1.Input file path of source and destination file.
2.Open source file in r (read) and destination file in w
(write) mode.
3.Read character from source file and write it to destination
file using fputc().
4.Repeat step 3 till source file has reached end.
5.Close both source and destination file.
INPUT

42 MUKUL
RAJ KASTOR 2K22/B6/68
OUTPUT

43 MUKUL
RAJ KASTOR 2K22/B6/68
EXPERIMENT-30
AIM: Program to read a file and after converting all lower
case to upper case letters write it to another file.
THEORY: It converts all the lower case characters from
uppercase and copied all the items to other file.
ALGORITHM: Step 1 − Set min to the first location
Step 2 − Search the minimum element in the array
Step 3 – swap the first location with the minimum value in
the array
Step 4 – assign the second element as min.
Step 5 − Repeat the process until we get a sorted array.
INPUT
1.Input file path of source and destination file.
2.Open source file in r (read) and destination file in w
(write) mode.
3.Read character from source file and write it to destination
file using fputc() and convert into uppercase by using
toupper().
4.Repeat step 3 till source file has reached end.
5.Close both source and destination file.

44 MUKUL
RAJ KASTOR 2K22/B6/68
INPUT

OUTPUT

45 MUKUL
RAJ KASTOR 2K22/B6/68
EXPERIMENT-31
AIM: Program to find the size of a given file.
THEORY: The idea is to use fseek() in C and ftell in C. Using
fseek(), we move file pointer to end, then using ftell(), we
find its position which is actually size in bytes.
ALGORITHM:
function findfileSize()
1.Open a file pointer fp in read only mode.
2.If fp is equals to null then
3.Print “File not found” and return -1.
4.Else count the file size.
5.Close the file.
6.Put the file pointer at the beginning of the file
7.Declare a integer variable result and initialize it with the
output of the ftell() function.
8.Close file pointer fp.
Return result.

46 MUKUL
RAJ KASTOR 2K22/B6/68
INPUT

OUTPUT

47 MUKUL
RAJ KASTOR 2K22/B6/68

You might also like