Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
12 views34 pages

Anish C

Uploaded by

bhandarip498
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views34 pages

Anish C

Uploaded by

bhandarip498
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

Tribhuvan University Faculty of Humanities and Social Sciences

Model Multiple Campus


Janakpurdham-4, Dhanusha
(Tribhuvan University Affiliated)

Lab Report for


Programming In C

Submitted By: Submitted To:


Name: Anish Karn Name: Er. Binay Yadav
Roll No: 27 Subject: C Programming
Programme: BCA (2nd Semester) Subject Code: CACS151

Signature:
Content Page
S.N. Title Date Page Signature

1. INTRODUCTION ABOUT LAB 2082/02/22 03-04

• Objectives
• Course Outcomes

2. Lab-1:-"Fundamentals of C Programming 2082/02/30 05-08


and Problem Solving Techniques"

3. Lab-2:- "Exploring Data Types, 2082/03/07 09-12


Operators, and Conditional
Expressions in C Programming"

4. Lab-3:- "Implementation of Decision- 2082/03/16 13-16


Making Constructs in C Language"
5. Lab-4:- "Implementation of For, While, 2082/03/25 17-20
and Do While Loops in C"

6. Lab-5:- "Practical Applications of 1D 2082/03/32 21-24


and 2D Arrays in C Programming"

7. Lab-6:- "Exploration of Function Types 2082/04/04 25-28


and Calls in C Programming"

8. Lab-7:- "Understanding Structures and 2082/04/12 29-32


File Handling in C Programming"

2|Page
INTRODUCTION ABOUT LAB

The C Programming Lab is an essential part of our BCA 2nd semester


curriculum. It is designed to provide practical experience with the C
language by allowing us to apply the concepts we learn in theory classes.
This lab helps us understand how to solve problems using logic and
implement them through real code.

During the lab sessions, we wrote and executed a wide range of programs,
from basic syntax and arithmetic operations to more complex topics like
arrays, functions, structures, and file handling. Each session helped us
improve our logical thinking, programming skills, and ability to debug
errors.
We also became familiar with the basic development steps of a C program:
writing and editing the code, compiling it to check for errors, linking
necessary libraries, and finally running the program to observe the
output.

Overall, this lab strengthened our foundation in programming and


prepared us to work confidently with not just C, but other programming
languages in the future.

3|Page
OBJECTIVES:

1. To introduce the basic knowledge of programming fundamentals of


C language.
2. To impart writing skill of C programming to the students and
solving problems.
3. To impart the concepts like looping, array, functions, pointers, file,
structure.

COURSE OUTCOME:
After completing this lab Course I will be able to:

1. Understand the logic for a given problem.


2. Write the algorithm of a given problem.
3. Draw a flow chart of a given problem.
4.Recognize and understand the syntax and construction of C
programming code.
5. Gain experience of procedural language programming.
6. Know the steps involved in compiling, linking and debugging C code.
7. Understand using header files.
8. Learn the methods of iteration or looping and branching.
9. Make use of different data-structures like arrays, pointers, structures
and files.
10. Understand how to access and use library functions.
11. Understand function declaration and definition.
12. Understand proper use of user defined functions.
13. Write programs to print output on the screen as well as in the files. 14.
Apply all the concepts that have been covered in the theory course.
15. Know the alternative ways of providing solution to a given problem.

4|Page
Lab-1

Title: "Fundamentals of C Programming and Problem solving


Techniques"

Objectives:
• To become familiar with the syntax and structure of the C
programming language.
• To understand the fundamental concepts of C such as variables,
data types, control structures, and functions.
• To apply logical and algorithmic thinking to solve programming
problems.
• To develop skills in writing, compiling, and debugging C programs.
• To build a foundation for advanced programming and software
development using C.

Theory:

C is a general purpose, high level programming language that provides a


structured approach to writing software. It is widely used for system
programming and application development due to its efficiency and control over
hardware. This lab focuses on introducing the basic syntax and structure of a C
program, including the use of header files, the main() function, and standard
input/output functions like printf() and scanf(). Through simple
programs, students learn how to write, compile, and execute C code and apply
basic problem-solving techniques.

Programs List :
1. Write a C program to display “This is my first C Program”.

5|Page
2. Write a C program to calculate area and circumference of a circle.

3.Write a C program to perform addition, subtraction, division and


multiplication of two numbers.

6|Page
4.Write a program to calculate simple and compound interest.

5. Write a C program to find the sum of first N natural numbers.

7|Page
Conclusion:

In this lab, I successfully implemented five basic programs in the C


language, each designed to build my understanding of its syntax and
logical structure.
The first program introduced the use of printf() for output. The second
and third programs helped me apply arithmetic operations to solve
realworld problems like calculating a circle's area and performing basic
mathematical operations on two numbers. The fourth program enhanced
my ability to use mathematical formulas and data types to compute both
simple and compound interest. The final program reinforced the use of
loops by calculating the sum of the first N natural numbers. Overall, this
lab deepened my understanding of input/output handling, variable
declaration, arithmetic expressions, and control structures, providing a
strong foundation for more advanced programming tasks.

8|Page
Lab-2

Title: "Exploring Data Types, Operators, and Conditional Expressions in


C Programming" Objectives:
• To understand and utilize different data types in C programming
effectively.
• To learn and apply various operators including arithmetic,
relational, logical, and ternary operators.
• To develop the ability to construct and evaluate expressions for
decision making.
• To implement conditional statements and control flow to solve
practical programming problems.
Theory:
In C programming, data types define the kind of data variables can hold,
such as integers (int), floating-point numbers (float, double), and
characters (char). Correct use of data types ensures efficient memory
usage and accurate computations.
Operators are symbols used to perform operations on variables and
constants. These include arithmetic operators for mathematical
calculations, relational operators for comparisons, logical operators for
combining conditions, and the ternary operator for concise conditional
expressions.
This lab emphasizes the application of these fundamental concepts to
solve programming problems involving decision making and data
manipulation. Programs such as checking palindromes, swapping
variables, and identifying Armstrong numbers illustrate how expressions
and control structures like if-else and the ternary operator enable logical
flow and problem solving in C.

Programs List:

9|Page
1.Write a C program to check whether a given number is palindrome or
not.

2.Write a program to swap values of two variables with and without


using third variable.

10 | P a g e
3. Write a program to input two numbers and display the largest
number.

4.Write a program to find the largest of three numbers using ternary


operators.

11 | P a g e
5. Write a program to check number is Armstrong or not.

Conclusion:
In this lab, I successfully implemented five programs that strengthened
my understanding of data types, operators, and expressions in C.
The first program helped me learn how to check if a number is a
palindrome using loops and conditional logic. The second program
taught me both standard and alternative methods to swap values using
and without using a third variable. In the third and fourth programs, I
practiced using if-else and ternary operators to compare numbers and
find the largest value. The fifth program deepened my understanding of
number manipulation by checking whether a number is an Armstrong
number using arithmetic and loop-based logic. Overall, this lab improved
my ability to write logical conditions, use different types of operators, and
apply expression evaluation techniques effectively in C programming.

12 | P a g e
Lab-3

Title: "Implementation of Decision-Making Constructs in C Language"


Objectives:
• To understand the use of decision control structures in C such as if,
if-else, if-else-if ladder, switch, and goto.
• To develop the ability to implement logical branching in programs
based on conditions.
• To apply appropriate decision-making constructs for solving
realworld problems.
• To enhance skills in writing efficient, readable, and structured C
programs using conditional statements.

Theory:

Decision control statements are fundamental elements in C programming that


allow a program to make choices and execute certain parts of code based on
conditions. These statements enable dynamic behavior by evaluating expressions
and determining the flow of execution accordingly.

The if and if-else statements are used to perform actions based on true or
false conditions, while the if-else-if ladder allows checking multiple
conditions in sequence. The switch statement is a more organized alternative
for selecting one of many options based on a specific value. Additionally, the
goto statement is used to transfer control to a labeled part of the program, though
its use is generally discouraged due to potential readability issues. In this lab,
these decision-making structures are applied in various programs such as
checking whether a number is prime, computing student grades, identifying
vowels or consonants, determining leap years, and calculating factorials. Mastery
of these constructs is essential for building logical, efficient, and interactive C
programs.

13 | P a g e
Programs List:
1.Write a Program to Check Whether a Number is Prime or not.

2.Write a program to compute grade of students using if else adder.


The grades are assigned as followed:
A. Marks<50 D
B. 50<=marks<60 C
C. 60<=marks<70 B
D. 70<=marks<80 B+
E. 80<=marks<90 A
F. 90<=marks<100 A+

14 | P a g e
3. Write a program to find whether a character is consonant or vowel
using Switch statement.

4. Write a program to check whether the entered year is leap year or not
(a Year is leap if it is divisible by 4 and divisible by 100 or 400.)

15 | P a g e
5. Write a program to find the factorial of a number.

16 | P a g e
Conclusion:
In this lab, I successfully implemented five programs that strengthened
my understanding of decision-making constructs in C programming.
The first program helped me learn how to check whether a number is
prime by using loops and conditional statements. The second program
taught me how to compute student grades using the if-else-if ladder for
multiple conditions. In the third program, I practiced using the switch
statement to identify whether a character is a vowel or a consonant. The
fourth program deepened my knowledge of logical conditions by
checking whether a year is a leap year based on divisibility rules. Finally,
the fifth program enhanced my understanding of loops and recursion by
calculating the factorial of a number. Overall, this lab improved my ability
to use various decision control structures effectively and write programs
that can handle complex logical flows in C.

LAB-4

Title: "Implementation of For, While, and Do While Loops in C"


Objective:
• To understand the use of loop control statements (for, while, and
do-while) in C programming.
• To develop skills in writing programs that use loops for repetitive
tasks efficiently.
• To apply loops and nested loops to solve practical problems such as
digit counting, sum calculation, and palindrome checking.
• To enhance logical thinking by generating sequences like the
Fibonacci series using loops.
• To implement input validation techniques using loops.

17 | P a g e
Theory:

Loops are fundamental control structures in C programming that allow a set of


instructions to be executed repeatedly based on a condition. They are essential
for performing repetitive tasks efficiently without writing redundant code. The
three main types of loops in C are the for loop, while loop, and do-while
loop.

The for loop is typically used when the number of iterations is known
beforehand, making it ideal for counting and fixed repetitions. The while loop
executes a block of code as long as a specified condition remains true, and it is
useful when the number of iterations depends on dynamic conditions. The
dowhile loop guarantees that the code block runs at least once before the
condition is tested, which is helpful in scenarios requiring initial execution prior
to condition checking.

Nested loops occur when one loop is placed inside another loop, enabling the
handling of more complex repetitive tasks such as processing multi-dimensional
data. In this lab, loops and nested loops are applied to solve problems including
counting digits, summing digits, checking for palindromes, generating Fibonacci
series, and validating input constraints, thereby improving problemsolving and
programming skills.

Programs List:
1.Write a program to count number of digits in a given integer.

18 | P a g e
2. Write a program to print the sum of digits of a number using for loop.

3.Write a program to check whether a number is Palindrome or not.

19 | P a g e
4.Write a program to generate Fibonacci series.

5. Write a c program that accept only 4 Digit number and display it.

20 | P a g e
Conclusion:
In this lab, I successfully implemented five programs that strengthened
my understanding of loop and nested loop concepts in C programming.
The first program helped me understand how to count digits in a number
using loop iteration. The second program taught me how to use a for loop
to calculate the sum of digits in an integer. In the third program, I used
loops and logic to check whether a given number is a palindrome. The
fourth program helped me generate the Fibonacci series by applying
iterative logic effectively. The final program focused on input validation
by allowing only a 4-digit number using a while loop. Overall, this lab
improved my ability to use for, while, and do-while loops to solve
realworld problems efficiently and with proper control flow.

21 | P a g e
LAB-5

Title: "Practical Applications of 1D and 2D Arrays in C Programming"


Objectives:
• To understand the concept and implementation of one-dimensional
and two-dimensional arrays in C programming.
• To learn how to store, access, and manipulate data using arrays.
• To perform basic operations such as insertion, searching for the
largest and smallest elements, and reversing elements in a 1D array.
• To apply array concepts in solving problems involving matrix
addition and multiplication.
• To enhance logical thinking and problem-solving skills using
structured data storage techniques.

Theory:

Arrays are a fundamental data structure in C programming that allow storage of


multiple values of the same data type under a single variable name. They are
essential for managing large sets of data efficiently. A one-dimensional (1D)
array is used to store a linear collection of elements, such as a list of numbers.
Basic operations on 1D arrays include insertion, traversal, finding the largest or
smallest elements, and reversing the order of elements.

On the other hand, two-dimensional (2D) arrays, also known as matrices, are
used to represent data in rows and columns. They are especially useful in
applications involving mathematical computations like addition and
multiplication of matrices. Performing operations on matrices requires nested
loops to access and manipulate data row-wise and column-wise.

This lab focuses on developing practical skills in working with both 1D and 2D
arrays, enhancing the ability to implement structured, efficient, and organized C
programs for solving real-world problems.

Programs List:
22 | P a g e
1.Write a program to insert 5 elements into an array and print the
elements of the array.

2.Write a Program to find the largest and smallest element in Array.

3.Write a Program to reverse the array elements in C Programming.

23 | P a g e
4.Write a program for addition of two matrices of any order in C.

24 | P a g e
5. Write a Program to multiply two 3 X 3 Matrices.

Conclusion:
In this lab, I successfully implemented programs that strengthened my
understanding of one-dimensional and two-dimensional arrays in C.
Through the first three programs, I learned how to insert elements, find
the largest and smallest values, and reverse the contents of a 1D array,
which improved my ability to manipulate linear data structures. The final
two programs involved operations on matrices, where I practiced matrix
addition and multiplication using nested loops. These exercises enhanced
my logical thinking and helped me understand how multidimensional
arrays can be used to solve complex mathematical problems efficiently.
Overall, this lab improved my skills in handling structured data and
writing clean, organized, and efficient C code using arrays.

25 | P a g e
Lab-6

Title: "Exploration of Function Types and Calls in C Programming"


Objectives:
• To understand the concept and importance of functions in C
programming.
• To learn how to define and use user-defined functions with and
without return types.
• To implement modular programming by breaking complex
problems into smaller, manageable functions.
• To practice function calls and parameter passing in solving
mathematical and logical problems.
• To enhance code reusability, readability, and efficiency using
function-based solutions.
Theory / Introduction:
In C programming, functions are fundamental building blocks used to
divide a program into smaller, manageable, and reusable sections. A
function is a self-contained block of code designed to perform a particular
task when it is called. Using functions not only promotes code reusability
but also improves the structure, clarity, and maintenance of the program.
Functions in C are mainly classified into two categories: library functions
and user-defined functions. Library functions such as printf() and scanf()
are pre-defined, while user-defined functions are created by the
programmer to perform specific tasks.
This lab focuses on the use of user-defined functions, especially those with
return types and parameters. These functions allow for efficient
problemsolving by handling tasks such as arithmetic operations,
determining the maximum and minimum between two values, checking
for even or odd numbers, and evaluating whether a number is prime,
Armstrong, or perfect.

26 | P a g e
Programs List:
1.Write a program to add, subtract, multiply and divide two integers
using user defined type function with return type.

2.Write a C program to find maximum and minimum between two


numbers using functions.

27 | P a g e
3.Write a C program to check whether a number is even or odd using
functions.

4.Write a C program to check whether a number is prime, Armstrong or


perfect number using functions.

28 | P a g e
5. Write a program to calculate factorial of a number using function.

Conclusion:

29 | P a g e
In this lab, I successfully implemented five programs that strengthened
my understanding of functions and modular programming in C.
The first program helped me learn how to perform arithmetic operations
using user-defined functions with return types. The second program
taught me how to find the maximum and minimum between two
numbers by using functions. In the third program, I practiced checking
whether a number is even or odd through function calls. The fourth
program deepened my knowledge by combining multiple functions to
check if a number is prime, Armstrong, or perfect. Finally, the fifth
program enhanced my skills in recursion and iteration by calculating the
factorial of a number using functions. Overall, this lab improved my
ability to write clean, reusable code by effectively using functions to solve
different problems in C programming.

Lab-7

Title: "Understanding Structures and File Handling in C Programming"


Objective:
• To understand the concept and use of structures for grouping
related data in C programming.
• To learn how to define, declare, and manipulate structures to store
complex data types.
• To practice reading and displaying structured data such as student
and company records.
• To gain practical experience in basic file operations including
reading from and copying file contents.
• To enhance skills in managing and organizing data efficiently using
structures and file I/O techniques.
Theory:

30 | P a g e
In C programming, a structure is a user-defined data type that allows
grouping variables of different types under a single name. Structures are
useful for representing real-world entities with multiple attributes, such
as student records or company details. By using structures, programmers
can organize complex data more efficiently and access related information
conveniently.
File handling in C provides the ability to read data from and write data to
files, enabling persistent data storage beyond program execution. Basic
file operations include opening, reading, writing, and closing files. These
operations allow programs to manage large amounts of data, transfer
information, and perform tasks such as copying file contents.
This lab focuses on using structures to store and manage data for multiple
records, as well as performing fundamental file operations to read and
copy file contents. Understanding these concepts is essential for
developing practical applications that require structured data
management and persistent storage.
Programs List:
1.Write a program to store information of 5 students in structure and
display it.

31 | P a g e
2. Write a program to create a structure named company which has
name, address, phone and no Of Employee as member variables. Read
name of company, its address, phone and no Of Employee. Finally
display these members‟ values.

3. WAP to read 10 students records with fields (roll,name,class,


marks in 5 subjects) and display their records along with their
percentage of marks obtained.
32 | P a g e
4.Write a c program to read and display the contents of a file?

5. Write a c program to copy the contents of one file to another?

33 | P a g e
Conclusion:
In this lab, I successfully implemented five programs that deepened my
understanding of structures and file handling in C.
The first three programs helped me learn how to define and use structures
to store and display information related to students and companies,
including handling multiple fields and calculating results such as
percentages. The last two programs introduced me to file handling
operations, where I practiced reading from and copying file contents
using standard I/O functions in C. These exercises strengthened my
ability to organize data efficiently and perform basic file operations.
Overall, this lab enhanced my knowledge of how structures and files are
used to manage real-world data in C programming.

34 | P a g e

You might also like