0% found this document useful (0 votes)
29 views

Japit-C File

The document provides a practical file of fundamentals of C programming submitted as a partial fulfillment for a bachelor's degree. It contains 30 programs on various C programming concepts like input/output, arithmetic operations, loops, arrays, functions, pointers, structures and file handling.

Uploaded by

maulikgupta5638
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)
29 views

Japit-C File

The document provides a practical file of fundamentals of C programming submitted as a partial fulfillment for a bachelor's degree. It contains 30 programs on various C programming concepts like input/output, arithmetic operations, loops, arrays, functions, pointers, structures and file handling.

Uploaded by

maulikgupta5638
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/ 43

Practical File

of
Fundamentals of C Programing
(23CS003)

Submitted in
partial fulfillment for the award of the degree of
BACHELOR OF ENGINEERING
in

COMPUTER SCIENCE & ENGINEERING

CHITKARA UNIVERSITY INSTITUTE OF ENGINEERING & TECHNOLOGY


CHITKARA UNIVERSITY

CHANDIGARH-PATIALA NATIONAL HIGHWAY


RAJPURA (PATIALA) PUNJAB-140401 (INDIA)

Submitted To: Submitted By:


Faculty name: Dr. Gurpreet Singh Student Name: Japit Singh
Designation: Mentor Roll No: 2310990612
Chitkara University, Punjab Sem: 2nd Semester Year 1

Session: 2023-2024
INDEX
S.No. Practical Page No. Date Teacher’s Signature
1. Write a Program to show the use to input (Scanf)/output
(Printf) statements and block structure of C-program by
highlighting the features of "stdio.h".
2. Write a program to add two numbers and display the
sum.
3. Write a program to calculate the area and the
circumference of a circle by using radius as the input
provided by the user.
4. Write a Program to perform addition, subtraction,
division and multiplication of two numbers given as
input by the user.
5. Write a program to evaluate each of the
following equations.
(i) V = u + at. (ii) S = ut+1/2at2 (iii) T=2*a+√b+9c (iv)
H=√b2+p2
6. Write a program to swap two variable:
a) By using temporary variable.
b) Without using temporary variable
7. Write a Program to find the greatest among
three numbers using:
 Conditional Operator
 If-Else statement
8. Write the following programs using switch case
statement:
 To check that an input alphabet is vowel
or consonant
 To check whether a number is positive,
negative or zero
9. Write a program using while loop to print the sum of
first n natural numbers.
10. Write a program to check a number is Armstrong or
not using For loop.
11. Write the program to count the digits in a number and
then print the reverse of the number also.
12. Write a program to generate the Fibonacci series.
13. Write a program to print the following
patterns: a)
*
**
***
****
*****
******

b)
*
**
***
****
*****
******

14. Write the program to print the following


pattern: 1 2 3 4 5 6
2 4 6 8 10 12
3 6 9 12 15 18
4 8 12 16 20 24
5 10 15 20 25 30
6 12 18 24 30 36
15. Write a program to check that the given number
is prime, Armstrong or perfect using the concept
of
functions.
16. Write a program to calculate the area and circumference
of a circle using functions.
17. Write a program to swap two variables using the
concept of call by value and call by reference.
18. Write a program to perform the following operations
on 1D-Array:
 Insert
 Update
 Delete
 Display
 Search
19. Write a program to calculate the sum of array elements
by passing it to a function.
20. Write a program to show the use of passing pointer as
arguments to the functions.
21. Write a program matrix multiplication using the concept
of 2D array
22. Write a program to transpose a given matrix.
23. Write a program to find the factorial of a number by
using the concept of recursion.
24 Write a menu driven C program to show the use of in-
built string functions like strlen, strcat, strcpy, strcmp,
strrev etc.
24 Write a Program in C to display the total number of
appearances of a substring provided as input by the user
in a given string.
25. Write a program to display the sum of the digits of a
number by using the concept of recursion.
26. Write a C program to add two distances in inch & feet
using the concept of structures.
27 Write a C program to add two complex numbers using
the concept of structures in C.
28 Write a program in C to store the information of five
employees using both concepts i.e. array of
structure and array within structure.
29 Write a Program in C to store and retrieve the
information about students of a university by using the
concept of file handling.
30 Write a Program in C to find and replace a specific
string in a file and also display the total number of
appearances of that string.
PROGRAM NO. – 1
Aim: Write a Program to show the use to input (Scanf)/output (Printf) statements and block structure of C-
program by highlighting the features of "stdio.h"
Coding:

Output:

PSEUDOCODE:
1. Initialize Num
2. Read Num
3. Display “Num”
4. Exit

Page | 1 Fundamentals of C programing(23CS003) Japit Singh


2310990612
Program No. – 2
Aim: Write a program to add two numbers and display the sum.

Coding:

Output:

PSEUDOCODE:
Initialize x and y
Read x and y
Initialize Sum
Compute Sum = x + y
Display “Sum”
Exit

Page | 2 Fundamentals of C programing(23CS003) Japit Singh


2310990612
Program No. - 3
Aim: Write a program to calculate the area and the circumference of a circle by using radius as the input provided
by the user.

Coding:

Output:

PSEUDOCODE:
Initialize Radius, Area, Circumference
Read Radius
Compute Area = 3.14159 * Radius * Radius
Compute Perimeter = 2 * 3.14159 * Radius
Display “Area” and “Circumference”
Exit

Page | 3 Fundamentals of C programing(23CS003) Japit Singh


2310990612
PROGRAM NO, - 4
Aim: Write a Program to perform addition, subtraction, division and multiplication of two numbers given as input
by the user.
Coding:

Output:

Page | 4 Fundamentals of C programing(23CS003) Japit Singh


2310990612
PSEUDOCODE:
Initialize num1 and num2
Read num1 and num2
Initialize Operator
Read Operator (+ - / *)
Switch Case used for the computation of the different cases i.e. (+,-,/,*)
Exit

Page | 5 Fundamentals of C programing(23CS003) Japit Singh


2310990612
Program No. – 5(a)
Aim: Write a program to evaluate each of the following equations.
(i) V = u + at
Coding:

Output:

PSEUDOCODE:
1. Initialize V, u, a, t as type float
2. Read V, u, a and t using scanf
3. Compute V = u + (a*t)
4. Display “V”
5. Exit.

Page | 6 Fundamentals of C programing(23CS003) Japit Singh


2310990612
Program No. – 5(b)
Aim: Write a program to evaluate each of the following equations.

(ii) S = ut+1/2at2

Coding:

Output:

PSEUDOCODE:
1. Initialize S, u, a and t as type float.
2. Read S, u, a and t
3. Compute S = (u*t) + 0.5*(a*t*t)
4. Display “S”
5. Exit

Page | 7 Fundamentals of C programing(23CS003) Japit Singh


2310990612
Program No. – 5(c)

Aim: Write a program to evaluate each of the following equations.


(ii) T=2*a+√b+9c

Coding:

Output:

PSEUDOCODE:
1. Include header file <math.h> for sqrt Function
2. Initialize T, a, b and c as type float.
3. Read the Values for T, a, b and c via scanf.
4. Check for the value b if less than 0 via if-else
condition
5. If 'if’ condition is satisfied print invalid value
6. If ‘else’ condition is satisfied then compute for the
Page | 8 Fundamentals of C programing(23CS003) Japit Singh
value of T
7. Display “T” 2310990612
8. Exit
Program No. – 5(d)

Aim: Write a program to evaluate each of the following equations.

(iii) H=√b2+p2
Coding:

Output:

PSUDEOCODE:
1. Include header file <math.h> for sqrt and pow Function
2. Initialize H, b and p as type float.
3. Read the Values for b and p using scanf
4. Check for the value of ‘b’ and ‘p’ using comparison
operators
5. Using if-else condition print and compute the appropriate
output
6. If ‘if’ condition is satisfied print invalid output.
7. If ‘else’ condition is satisfied compute the value of H and
print it.
8. Display “H”
9. Exit

Page | 9 Fundamentals of C programing(23CS003) Japit Singh


2310990612
Program No. – 6(a)
Aim: Write a program to swap two variables:
a) By using temporary variable.

Coding:

Output:

PSEUDOCODE:
1. Initialize Num1 and Num2 as type int.
2. Initialize a Temporary Variable “Temp” as type int.
3. Read Num1 and Num2
4. Display Num1 and Num2 Before Swap
5. Initialize Temp = Num1
Num1 = Num2
Num2 = Temp
6. Display Num1 and Num2 after Swap.
7. Exit

Page | 10 Fundamentals of C programing(23CS003) Japit Singh


2310990612
Page | 11 Fundamentals of C programing(23CS003) Japit Singh
2310990612
Program No. – 6(b)
Aim: Write a program to swap two variables:
b) Without using temporary variable

Coding:

Output:

PSEUDOCODE:
1. Initialize num1 and num2 as type int.
2. Read num1 and num2.
3. (Where num1 is represented by ‘a’ and num2 is represented by
‘b’
4. Display a and b before Swap.
5. Compute:
num1 = num1 + num2
num1 = num1 – num2
num1 = num1 – num2
6. Display num1 and num2 after Swap.
7. Exit Fundamentals of C programing(23CS003)
Page | 12 Japit Singh
2310990612
Program No. – 7(a)
Aim: Write a Program to find the greatest among three numbers using:

 Conditional Operator

Coding

Output:

Page | 13 Fundamentals of C programing(23CS003) Japit Singh


2310990612
PSEUDOCODE:
Initialize num1, num2, num3 as integers
 Get input of the values from the user
(Where num1 is ‘x’, num2 is ‘y’ and num3 is ‘z’.
 Read x, y, and z from the user
 Initialize a variable Greatest as an integer
Using if-else condition check for the max number
If (num1 > num2) then
If (num1 > num3) then
Set Greatest = num1 (i.e. is ‘x’)
Else
Set Greatest = num2 (i.e. is ‘y’)
Else:
If (num2 > num3) then
Set Greatest = num2 (i.e. is ‘y’)
Else
Set Greatest = num3 (i.e. is ‘z’)
 Output "Greatest: " followed by the value of Greatest
 Exit

Page | 14 Fundamentals of C programing(23CS003) Japit Singh


2310990612
Program No. – 7(b)
Aim: Write a Program to find the greatest among three numbers using:

 If-Else statement

Coding:

Output:

Page | 15 Fundamentals of C programing(23CS003) Japit Singh


2310990612
Page | 16 Fundamentals of C programing(23CS003) Japit Singh
2310990612
PSEUDOCODE:
Initialize variables x, y, z as integers.
1. (Where x is ‘num1’, y is ‘num2’, and z is ‘num3’
 Initialize variable Greatest as an integer
(This variable is store the value for the end)
 Display "Enter the Three Numbers: ".
 Read x, y, and z from the user.
 Using if-else condition check for the
Greatest value.
If (x > y and x > z) then
Set Greatest = x
Else if (y > x and y > z) then
Set Greatest = y
Else
Set Greatest = z
 Dispaly “Greatest”
 Exit

Page | 17 Fundamentals of C programing(23CS003) Japit Singh


2310990612
Program No. – 8(a)
Aim: Write the following programs using switch case statement:

 To check that an input alphabet is vowel or consonant

Coding:

Page | 18 Fundamentals of C programing(23CS003) Japit Singh


2310990612
Output:

PSEUDOCODE:
1. Include header file <ctype.h> to access toupper Function.
2. (Including this header file isn’t necessary we can check for characters in small case. This is
included to insure uniformity)
3. Initialize Alphabet as type char.
4. Read Alphabet.
5. (Here by using switch case statement we compare the value that the user inputs by putting it
in the switch case and checking it against all the cases. This can also be done with the help
of an if-else condition by putting multiple else if conditions)
6. Switch (Alphabet):
a. Case ‘A’:
Display “A is a Vowel”
Break
b. Case ‘E’:
Display “E is a Vowel”
Break
c. Case ‘I’:
Display “I is a Vowel”
Break
d. Case ‘O’:
Display “O is a Vowel”
Break
e. Case ‘U’:
Display “U is a Vowel”
Break
f. Default:
Display “Consonant”
7. Exit

Program No. – 8(b)


Aim: Write the following programs using switch case statement:

 To check whether a number is positive, negative or zero


Coding:

Page | 19 Fundamentals of C programing(23CS003) Japit Singh


2310990612
Output:

Page | 20 Fundamentals of C programing(23CS003) Japit Singh


2310990612
PSUEDOCODE:
1. Initialize Num as type int.
2. Read Num
3. Switch ((Num>0) - (Num<0)):
4. (The expression (number > 0) - (number < 0) is used to categorize
the number. It exploits the fact that relational operators return 1 if
true and 0 if false in C. So, for a positive number, (number > 0) is
1 and (number < 0) is 0, resulting in 1. For a negative number, the
calculation results in -1, and for zero, it results in 0.)
a. Case 1:
Display “Positive”.
Break
b. Case -1:
Display “Negative”.
Break
c. Default:
Display “Zero”.
5. Exit

Page | 21 Fundamentals of C programing(23CS003) Japit Singh


2310990612
Program No. – 9
Aim: Write a program using while loop to print the sum of first n natural numbers.

Coding:

PSEUDOCODE:
Initialize variable Num and sum as int.
Put sum = 0 and in while loop continue till
Num >0.
In while loop increment sum by num while
num is also getting decrement.
Print the sum.

Output:

Program No. – 10

Aim: Write a program to check a number is Armstrong or not using For loop.

Page | 22 Fundamentals of C programing(23CS003) Japit Singh


2310990612
Coding:

PSEUDOCODE:
Initialize variables num,sum,rem,temp as int.
Put temp = num(for comparison).
In while loop(num>0) use % operator to get
the digits one by one and increment it to sum.
Reduce num by using num/10.
Compare sum to temp(if yes ‘armstrong’ else
no.
Print the results

Output:

Program No. - 11

Aim: Write the program to count the digits in a number and then print the reverse of the number also.
Page | 23 Fundamentals of C programing(23CS003) Japit Singh
2310990612
Coding:

Output:

PSEUDOCODE:
Initialize variables count,num,temp as int.
Using a while loop get the reverse of the number and
continue the while loop till num>0 and also get the count.
Using num=num/10
Print the count and the reversed number

Program No. – 12

Aim: Write a program to generate the Fibonacci series.


Page | 24 Fundamentals of C programing(23CS003) Japit Singh
2310990612
Coding:

Output:

PSEUDOCODE:
Initialize the variables num,sum,a,b as int.
Using for loop and algo
(sum= a+b) where values of a and b are being
changed repeatedly
Till the i<num condition is there
Print the series

Program No. -13(a)

Page | 25 Fundamentals of C programing(23CS003) Japit Singh


2310990612
Aim: Write a program to print the following patterns:

*
**
***
****
*****
******

Coding:

Output:

PSEUDOCODE:
Initialize variable n(for no of rows).
Using two for loops and correct conditions
(Outer loop i<n+1 ; Inner loop j<i : for stars)
After each loop run print an empty space so to
continue from the next line.

Program No. – 13(b)

Page | 26 Fundamentals of C programing(23CS003) Japit Singh


2310990612
Aim: Write a program to print the following patterns:

*
**
***
****
*****

Coding:

PSEUDOCODE:
Output:
Initialize variable n(for no of rows).
Using two for loops and correct condition for
the loops print the spaces and stars accurately
(Outer loop i<n; Inner loop j<n-i : for spaces ) and
Inner loop(j<i+1: for stars)
After each loop run print an empty space so to
continue from the next line.

Program No. -14

Page | 27 Fundamentals of C programing(23CS003) Japit Singh


2310990612
Aim: Write the program to print the following pattern:

1 2 3 4 5 6
2 4 6 8 10 12
3 6 9 12 15 18
4 8 12 16 20 24
5 10 15 20 25 30
6 12 18 24 30 36

Coding:

Output:

PSEUDOCODE:
Initialize variable n(for no of rows).
Using two for loops and correct conditions
(Outer loop i<=n and j<=n for inner loop).
Print the pattern using (i*j).
After each loop run print an empty space so to
continue from the next line.

Page | 28 Fundamentals of C programing(23CS003) Japit Singh


2310990612
Program No. – 15

Aim: Write a program to check that the given number is prime, Armstrong or perfect using the concept of
functions.

Coding:

PSEUDOCODE:
Get number:Fundamentals
Prompt user to
of enter a number and store it.
C programing(23CS003)
Page | 29 Japit Singh
 Check prime: Call a function to check if the number is prime
2310990612
and print appropriate message.
 Check perfect: Call a function to check if the number is perfect
Program No. – 16
Page | 30 Fundamentals of C programing(23CS003) Japit Singh
2310990612
Aim: Write a program to calculate the area and circumference of a circle using functions.

Coding:

Output:

PSEUDOCODE:
Initialize variable radius(for the radius) as
double.
Call the functions area and circumference which
namely compute the area and circumference of the
circle.
Then print the result i.e. area and circumference.

Program No. – 17
Page | 31 Fundamentals of C programing(23CS003) Japit Singh
2310990612
Aim: Write a program to swap two variables using the concept of call by value and call by reference.

Coding:

Output:

Page | 32 Fundamentals of C programing(23CS003) Japit Singh


2310990612
PSEUDOCODE:
Define callvalue(num1, num2) swapping num1
and num2.
Define callreference(Num1, Num2) swapping
values pointed by Num1 and Num2.
Read num1 and num2 from user input.
Call callvalue(num1, num2) and print num1 and
num2.
Call callreference(&num1, &num2) and print
num1 and num2.

Program No. – 18

Aim: Write a program to perform the following operations on 1D-Array:


 Insert
 Update
 Delete
 Display
 Search

Coding:

Page | 33 Fundamentals of C programing(23CS003) Japit Singh


2310990612
Program No. – 19
Aim: Write a program to calculate the sum of array elements
by passing it to a function.

Coding:
PSEUDOCODE:
Get array size: Prompt user for the number of elements and
store it in a variable.
Input elements: Create an array of the given size and prompt
Page | 34 the user to enter each element, storing them
Fundamentals inprograming(23CS003)
of C the Japit Singh
corresponding array indices. 2310990612
Perform operations: Call functions for insert, update, delete
(based on user input for element and index), handling potential
PSEUDOCODE:
Get array size: Prompt user to enter the number of elements in the
array and store it in a variable.
Create array: Declare an integer array with size entered by the user.
Input elements: Loop through each element of the array, prompt the
user to enter a value, and store it in the corresponding array index.
 Calculate sum: Call a function SumofArray that takes the array and
its length as input, iterates through the array, adds each element to a
running total (Sum), and returns the final sum.
 Print sum: Print the calculated sum of all elements in the array.

Output:

Program No. – 20

Aim: Write a program to show the use of passing pointer as


arguments to the functions.

Coding:

Page | 35 Fundamentals of C programing(23CS003) Japit Singh


2310990612
Output:

PSEUDOCODE:
Initialize number as int equal to 5.
Print the original number.
Call the function square by passing address of the
variable and use the concept of pointers.
Now in function from the address get the value of
the variable using *.
Compute the result and return the squared number.

Program No. – 21

Aim: Write a program matrix multiplication using the concept of 2D array

Page | 36 Fundamentals of C programing(23CS003) Japit Singh


2310990612
Coding:

Output:

Page | 37 Fundamentals of C programing(23CS003) Japit Singh


2310990612
PSEUDOCODE:
Prompt for dimensions and elements of two matrices
(matrix1 and matrix2
Validate if matrix multiplication is possible (columns of
matrix1 must equal rows of matrix2).
If valid, initialize a result matrix (matrix3) and perform
multiplication: for each cell in matrix3, calculate the dot
product of the corresponding row from matrix1 and column
from matrix2.
 Print the resulting matrix (matrix3) after performing
multiplication.
Display an error message if the dimensions do not allow for
multiplication.

Program No. – 22

Aim: Write a program to transpose a given matrix.

Coding:

Page | 38 Fundamentals of C programing(23CS003) Japit Singh


2310990612
Output:
PSEUDOCODE:
Prompt user for matrix dimensions m and n, then collect matrix
elements.
 Initialize a 10x10 matrix and fill it with user inputs.
For each element in the matrix, swap matrix[i][j] with matrix[j][i] for
all valid i and j.
Correct error: only swap when i < j to avoid re-swapping.
 Print the transposed matrix using its new dimensions n as rows and m
as columns.
Return from the program.

Page | 39 Fundamentals of C programing(23CS003) Japit Singh


2310990612

You might also like