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

C Lab

Lab

Uploaded by

Mausam Jha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

C Lab

Lab

Uploaded by

Mausam Jha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Tribhuvan University

Institute of Engineering
Purwanchal Campus, Dharan

C-Programming Lab Manual

Prepared by:
Pravin sangroula
IOE, Purwanchal Campus
[email protected]
1
Table of Contents
INTRODUCTION ....................................................................................................................................................3
LAB SHEET NO.1 [To be familiar with C- Programming] .....................................................................................4
LAB SHEET NO.2 [To be familiar Data types, Constants, Operators and Expressions] ........................................4
LAB SHEET NO.3 [To be familiar with selective structure (branching)] ...............................................................6
LAB SHEET NO.4 [To be familiar with Unformatted and Formatted I/0] ..............................................................7
LAB SHEET NO.5 [To be familiar with LOOPS] ...................................................................................................8
LAB SHEET NO.6 [To be familiar with FUNCTIONS:] ........................................................................................9
LAB SHEET NO.7 [To be familiar with Array] ....................................................................................................10
LAB SHEET NO.8 [To be familiar with Pointers].................................................................................................10
LAB SHEET NO.9 [To be familiar with Structure] ...............................................................................................10
LAB SHEET NO.10 [To be familiar with String] ..................................................................................................11
LAB SHEET NO.11 [To be familiar with File Handling] ......................................................................................11

2
INTRODUCTION
The lab report is to be submitted to the department of the Electronics and Computer Engineering.
Student must submit the solution of all the problems stated in the lab sheet to qualify for the final
examination.
Thing to be included in the lab sheet:

1. Cover page
2. Title
3. Objective
4. Algorithm
5. Flowchart
6. Code
7. Output
8. Discussion and Conclusion.

[Note: A sample of lab sheet can be obtained from the Department of Electronics and Computer
Engineering.]

3
LAB SHEET NO.1 [To be familiar with C- Programming]
1. WAP to display hello world.
2. WAP to display your name, roll number and address.
3. WAP to add two integer variables and print sum.
4. WAP to multiply two integer variables and print product.
5. WAP to calculate and display the simple interest.
6. WAP to calculate the area of the circle.

LAB SHEET NO.2 [To be familiar Data types, Constants,


Operators and Expressions]
1. WAP to declare integer, float and character variable. Initialize them with certain value
and print those values. Also display the size of variables.
2. WAP to swap the values of the variable with and without using third variable.
3. WAP to calculate the area and volume of a cylinder using pre-processor directive for
value of PI.
4. WAP to input two numbers from user and display the minimum using conditional
operator.
5. WAP to display whether a number is even or odd using conditional operator.

4
6. What are the output of the following programs:

#include <stdio.h>

int main()

int a = 5, b = 9;

printf("a = %d, b = %d\n", a, b);

printf("a&b = %d\n", a & b);

printf("a|b = %d\n", a | b);

printf("a^b = %d\n", a ^ b);

printf("~a = %d\n", ~a);

printf("(b<<2)+(a<<1) = %d\n",(b<<2)+(a<<1));

printf("(b>>1)+(a>>1) = %d\n",(b>>1)+(a>>1));

return 0;

5
LAB SHEET NO.3 [To be familiar with selective structure
(branching)]
1. WAP to check whether a number is negative, positive or zero.
2. WAP to find maximum between three numbers entered by the user.
3. WAP to input a character from the user and check whether the character is vowel or
consonant.
4. WAP to input a character from the user and check whether the character is Alphabet
or not. If the character is Alphabet then show whether it is uppercase or lowercase.
5. WAP to check whether the year entered by the user is leap year or not.
6. WAP to check whether the number entered by the user is divisible by 5 and 11 or not.
7. WAP to find the all the roots of a quadratic equation.
8. WAP to input two numbers and operator among [ + , - ,* , / ]. If user enters + then the
program should perform the addition of the number and display the sum. If user enters
– then the program should perform subtraction of number and display the difference
and so on for * and /.
9. WAP in C to input marks of five subjects C-programming, Physics, Maths, Applied
Mechanics and Basic electrical. Display whether the student passed or failed. Take
F.M=100 and P.M.=40 For passed students calculate percentage and grade according
to following:
Percentage >= 90% : A
Percentage >=80% : B
Percentage >= 70% : C
Percentage >= 60% : D
Percentage >= 40% : E
10. WAP to input a number from user. If user enters a number less than or equal to zero
then program should just display the number. If user enters 1 the program should
display output as neither prime nor composite, if user enters 2 the program should
display output as smallest and only even prime number. If user enters any number
greater than 2 the program should check whether the number is prime or not, also if
the number is not prime the program should display whether it is even or odd.

6
LAB SHEET NO.4 [To be familiar with Unformatted and
Formatted I/0]
1. WAP to get your name, address and display using unformatted I/O.
2. WAP to get a character form the user using unformatted I/O and display the ASCII
value of the entered character.
3. WAP to display the output as [take a=15, b=20.43, c=35]:

A= 15|15 | 15|15 | 15|15 | 15|15 | 15|15 |


B= 20.43|20.43 | 20.43|20.43 | 20.43|20.43 | 20.43|20.43 | 20.43|20.43 |
C= 35|35 | 35|35 | 35|35 | 35|35 | 35|35 |
4. WAP to display the output as below using formatted I/O [take char a[]=”I Love
Nepal”].
I
IL
I LO
I LOV
I LOVE
I LOVE N
I LOVE NE
I LOVE NEP
I LOVE NEPA
I LOVE NEPAL

7
LAB SHEET NO.5 [To be familiar with LOOPS]
1. WAP to read 10 numbers from user and find their sum and average.
2. WAP to display the multiplication table of integer given by the user.
3. WAP to input two integer values from the user and print the even number between the
range of integers. Also count the even number and display the count as well [Hint: if
user enters 10 and 100. The program should print and count even numbers between 10
and 100].
4. WAP to display sum of series: 1 + 1/2 + 1/3 + 1/4 + 1/5 ... 1/n
5. WAP to display sum of series: 1 + 1/2! + 1/3! + 1/4! + 1/5! ... 1/n!
6. WAP to display sum of series: x + x2/2! + x3/3! + x4/4! + x5/5! ... xn/n!
7. WAP to find the value cos(x) without using cos(x) library function.
8. WAP to display weather a number is Armstrong or not.
9. WAP to display the first n terms of Fibonacci series.
10. WAP to display the number in reverse order.
11. WAP to check whether a number is a palindrome or not.
12. WAP to find HCF and LCM of two numbers.
13. WAP to print the following patterns:

1 12345 * 1
12 1234 *** 23
123 123 ***** 456
1234 12 ******* 7 8 9 10
12345 1 ********* 11 12 13 14 15

123454321 54321

1234321 5432

12321 543

121 54

1 5

8
LAB SHEET NO.6 [To be familiar with FUNCTIONS:]
1. Write a program to add, subtract, multiply and divide two integers using user defined
function add(), sub(), mul() and div().
2. WAP to display sum of series: x + x2/2! + x3/3! + x4/4! + x5/5! ... xn/n!. User defined
function factorial() and power() should be used to calculate the factorial and power.
3. WAP to calculate factorial using Recursion.
4. WAP to display the nth Fibonacci number using recursion.
5. WAP to take two numbers in main(). Write a function Swap() to swap the values of
the variables. Print the swapped values in main().
6. WAP to take two float number in main(). Write a function single user define function
calculator() to perform the addition, subtraction and multiplication. The sum,
difference and product should be displayed from the main() function. [Use the
concept of pass by reference.].
7. WAP to input a integer number in main(). Write a user define function isPrime() to
calculate whether the number is prime of not. Print whether the number is prime or
not from the main().
8. WAP to illustrate the concept of global and static variables.

9
LAB SHEET NO.7 [To be familiar with Array]
1. WAP to store 10 integer elements in an array and print it.
2. WAP to calculate and print the sum and average of n elements of array.
3. WAP to sort n elements of array in descending order.
4. WAP to count the frequency of the elements in an array.
5. WAP to pass 1D array to the minmax() function. The function should calculate the
maximum and minimum among the elements of the array. Print the maximum and
minimum in the main() function.
6. WAP to multiply matrix of different size if possible using 2D array.
7. WAP to find the transpose of the matrix.
8. WAP to find the sum of the rows and column of the matrix.

LAB SHEET NO.8 [To be familiar with Pointers]


1. WAP to find the sum and difference of two number using pointers .
2. WAP to read two values from the user in main(). Write a function calculate() to
calculate sum, product, difference and quotient of the numbers. Print the sum,
product, difference and quotient in the main function using pass by reference
concept.
3. WAP to access the elements of the array using the pointers.
4. WAP to illustrate the concept of array of pointers and pointer to the array.

LAB SHEET NO.9 [To be familiar with Structure]


1. WAP to store and print the employee number, name, address and salary of the n
employee using the structure.
2. WAP to add two distance (feet-inch) using the structure.
3. WAP to read and print the values of structure using pointer to structure.
4. WAP to define a structure employee with members empno, name, salary and
address. Main() should always ask input for the particular function call until user
exits the program. And create functions as below:
a. Input(): To read a record of employee.
b. Display(): To display the all the records.
c. Updatesal(): To update the particular salary of the employee.

10
LAB SHEET NO.10 [To be familiar with String]
1. WAP to input and display a string.
2. WAP to illustrate the use of string functions (strlen, strcpy, strcat, strcmp, strrev).
3. WAP to count the length of string without using string function.
4. WAP to copy the string without using string function.
5. WAP to compare two string without using string function.
6. WAP to concatenate two string using user define function.
7. WAP to input array of strings and also display the strings in alphabetic order.
8. WAP to check whether the string is palindrome or not.

LAB SHEET NO.11 [To be familiar with File Handling]


1. WAP to create and store string using in a text file. Also display the string from the
text file.
2. WAP to illustrate the use of single character input/output in file (fgetc() and fputc()).
3. WAP to illustrate the use of fscanf() and fprintf().
4. WAP to define a structure employee with members empno, name, salary and
address. Main() should always ask input for the particular function call until user
exits the program. Create binary file employee.dat and functions as below:
a. AddRecord(): To add record of employee in the file.
b. DisplayRecord(): To display all the records from the file.
c. UpdateRecord(): To update the particular salary of the employee in the file.
d. DeleteRecord(): To delete the particular record of employee from the file.

11

You might also like