C Lab
C Lab
Institute of Engineering
Purwanchal Campus, Dharan
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.
4
6. What are the output of the following programs:
#include <stdio.h>
int main()
int a = 5, b = 9;
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]:
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.
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.
11