Uploaded by Akash Tripathi

CP Lab program list

advertisement
C- Programming Lab Manual
________________________________________________________________________
Experiment Set 1: Basic Statements and operators (Lab Assigned: 01)
1. WAP to print out the results of different arithmetic operations (+, -, ×, /, %) Performed
using two numbers (say 20, 10).
2. Write a C Program to Read Two Integers M and N & Swap their Values with or without
using a temporary variable.
3. Ramesh’s basic salary is input through the keyboard. His dearness allowance is 40% of basic
salary, and house rent allowance is 20% of basic salary. Write a program to calculate his gross
salary
4. In a class, marks of 5 students are given as follows 80, 85, 70, 76, 60. WAP to Calculate the
average and display it.
5. Temperature of a city in Fahrenheit degrees is input through the keyboard. Write a program
to convert this temperature into Centigrade degrees
Do it yourself (Homework):
1. If a five-digit number is input through the keyboard, write a program to calculate the sum
of its digits.
2. A cashier has currency notes of denominations 10, 50 and 100. If the amount to be
withdrawn is input through the keyboard (in multiples of 10 only & maximum 990), find
the total number of currency notes of each denomination the cashier will have to give to
the withdrawer.
Experiment Set 2: Conditional statements (Lab Assigned: 01)
1. Write a C program to check whether a number is ODD or EVEN.
2. Write a C program to find maximum and minimum number among three numbers with or
without using ternary operators.
3. Write a program to print the month name corresponding to the digit enter from the user using
switch statement. For example if user enter 1 then print “January” on 2 print “February”…..
4. Write a C program to input three sides of a triangle and check whether the triangle is valid
or not.
5. Write a C program to input marks of five subjects and calculate the percentage. Also
Calculate Grade according to the following:
Percentage>= 90% A
Percentage>=80% B
Percentage>=70% C
Percentage>=60% D
Percentage>=40% E
Percentage<40% Fail
Do it yourself (Homework):
1. Write a C program to check a given year is leap-year or not.
2. Write a C program to input the coefficients of a quadratic equation and find the roots of an
Equation.
1.
2.
3.
4.
5.
Experiment Set 3: Iterative statements (Lab Assigned: 01)
Write a program whether the enter number is prime or not.
WAP to find sum of even numbers which are divisible by 2,3 and 5 up to ‘n’ numbers
where n is entered from user.
WAP to print Fibonacci series up to ‘n’ terms where n is entered from user.
WAP to check whether the entered integer number is palindrome or not.
WAP to find the binary equivalent of a an integer number entered from user also count the
number of 1’s and number of 0’s in the resultant binary number.
Do it yourself (Homework):
1. WAP to print number in words (Using while and switch statements).
2. Write programs to print following patterns*
0
* * *
1 0 1
* * * * *
2 1 0 1 2
* * * * * * *
3 2 1 0 1 2 3
1
22
33 3
4 4 4 4
5 5 5 5 5
1
232
34543
4567654
*
*
*
*
*
*
*
*
* *
* * *
* *
*
1
1
1
1
1
1
2
3
1
3
1 4
6
4
5
10
10 5
1
1
1
Experiment Set 4: Arrays and Strings (Lab Assigned: 01)
1.
2.
3.
4.
5.
Write a program to find maximum and minimum number from an array.
Write a program to calculate average of n numbers.
Write a program to sort numbers in ascending and descending order.
WAP to find the number of occurrences of every number exist an array of size 10.
Write a program to demonstrate the use of following functions- strlen(), strlwr(),
strupr(), strcpy(), strncpy(), strcmp(), strcmpi(), strchr(), strrchr().
Do it yourself (Homework):
1. Write a program to find how many numbers in an array are positive, negative and zero.
2. Write a program to enter a string and give output in ASCII codes for each character in
string.
___________________________________________________________________________
1.
2.
3.
4.
Experiment Set 5: Matrices (Lab Assigned: 01)
Write a program to enter and print a matrix. Also calculate sum and product of diagonal
elements of the matrix.
Write a program to find transpose of a matrix.
WAP to find the addition of two matrices A and B. Print appropriate message in case
matrices A and B are not compatible for addition.
Write a program to find reverse of a string without using library function.
Do it yourself (Homework):
1. Write a program to find largest and smallest number from matrix.
2. WAP to find the multiplication two matrices A and B. Print appropriate message in case
matrices A and B are not compatible for multiplication.
________________________________________________________________________
Experiment Set 6: Functions and pointers: Part-1 (Lab Assigned: 01)
1.WAP to demonstrate the working of single and double pointer. (like use of &, *, **)
2.WAP to add two numbers using pointer.
3.WAP to swap two numbers using pointer.
4.Write a program to demonstrate the different way of defining function like
(a) Create a function without returning any value and without argument.
(b) Create a function which return the sum of two variables passed in it.
(c) Create a function which return the sum of all elements of an array passed in the
function.
Do it yourself (Homework):
1. WAP to convert decimal number into binary number using function.
2. WAP to perform following operation on matrix (3*3) using function and pointer
1. transpose of matrix
2. check weather symmetric or not
__________________________________________________________________________
Experiment Set 7: Functions and pointers: Part-2 (Lab Assigned: 01)
1. WAP to find the multiplication of matrices A and B into matrix C where the initialization
of matrices A and B should be done by a function initMat(), printing of matrices should
be done by printMat() and multiplication should be done by mulMat(). You need to pass
the matrices into functions according to need.
2. Write a program to print Fibonacci series using recursive function.
3. Write a program to print factorial of a number using recursive function.
4. Write a program to print sum of digits of an integer number using recursive function.
Do it yourself (Homework):
1. WAP to swap two number using function
1.using call by value
2.call by reference
2. WAP program for passing an array as a pointer into a function where the function will sort
the elements of the array into ascending order and sorted array is returned from the function.
___________________________________________________________________________
Experiment Set 8: Pre-processor directives and Macros (Lab Assigned: 01)
1. Calculate the area of circle by using #define preprocessor(Value of pie)
2. Calculate the area of circle by using function call macros.
4. Find the greater no among three nos. using function call macros.
5. Write a program to implement predefines macros
_DATE_
_FILE_
_LINE_
_STDC_
_TIME_
Do it yourself (Homework):
1. Find the smaller of three nos using #IF #ELSE #ELIF directive.
2.Write a program to print error message using #err directive
___________________________________________________________________________
1.
2.
3.
4.
Experiment Set 9: Structure and union (Lab Assigned: 02)
Define a data type for storing complex number and implement addition, subtraction,
multiplication and modulus operations for the defined data type.
Create a structure to specify data of customers in a bank. The data to be stored is:
Account number, Name, Balance in account.
i.
Write a function to print the Account number and name of each customer with
balance below Rs. 100
ii.
If a customer requests for withdrawal or deposit, it is given in the form:
Account Number, Amount, Code (1 for deposit, 0 for withdrawal)
If on withdrawal the balance falls below Rs. 100 then program give a message
” Insufficient Balance”.
Develop a phonebook application. It should be able to store, modify and list entries
present in the phonebook. A phone book entry consists of the name of the person and
his contact information. The name of the person consists of his first name and family
name. The contact information consists of the landline number and the mobile number
of the person.
Create a structure Employee1 that holds the information- Id (integer), Name (character
[]), Salary (long).Create a union Employee2 that also holds the same information as
well as same data type as that of structure Employee1. Write a program in C to find and
display the size of structure Employee1 and union Employee2.
5. Create a structure called Library to hold accession number, title of the book, author
name, price of the book and flag indicating whether book is issued or not. Write a menu
driven program that implements the working of a library. The menu options should be:
i.
Add book information
ii.
Display book information
iii.
List the count of books in a library
iv.
List all books of given author
v.
Exit
Do it yourself (Homework):
1. Define a structure data type called DATE for storing dates. The type contains three
integer members: day, month and year. Implement the following operations for the
defined data type:
(i) Isvalid: Check whether the entered date is valid or not, e.g. 31-2-2018 is
not valid date since February does not have 31 days.
(ii) Nextdate: Finds the next date e.g. if the current date is 31-1-2018, then
the result of Nextdate operation is 1-2-2018.
(iii)Datediff: Finds the difference between two dates.
2. Define structure data type TRAIN_INFO. The type contains:
i. Train No: interger type
ii. Train name: string
iii. Departure time: aggregate type TIME
iv. Arrival time: aggregate type TIME
v. Start station: string
vi. End station: string
The structure type TIME contains two integer members: hours and minute. Maintain a
train timetable and implement the following operations:
(i) List all the trains (sorted according to train number) that depart from
particular station.
(ii) List all the trains that depart from a particular station at particular point.
(iii)List all the trains that depart from a particular station within next one
hour of a given time.
(iv) List all the trains between a pair of start station and end station.
______________________________________________________________________
Experiment Set 10: Files (Lab Assigned: 02)
1.WAP in C to read name and marks of 10 students from user and store them in a file.
2.WAP in C to create two files and add the content of one file at the end of another file.
3 Write a program to read multiple number of strings from the user and write them to a file
using fputs() and read the same strings from file using fgets() and display on the output screen.
4. Write a program to receive detail (like name, roll no. etc) of students and write them into
file. Also display these records of students on screen.
Do it yourself (Homework):
1. Suppose there is a file containing records of employees and each record contain Employee
id, Name and Basic salary. Write a program to read these records and display them in sorted
order by Employee id.
2 Write a program to carry out the following:
− To read a text file “TRIAL.txt” consisting of a maximum of 30 lines of text, each line with a
maximum of 80 characters.
− Count and display the number of words contained in the file.
− Display the total number of four letter words in the text file.
Assume that the end of a word may be a space, comma or a full-stop followed by one or more
spaces or a newline character.
Download