Professional Documents
Culture Documents
net/publication/306482093
CITATIONS READS
0 21,992
1 author:
Bhaskar Mondal
National Institute of Technology Patna
55 PUBLICATIONS 569 CITATIONS
SEE PROFILE
Some of the authors of this publication are also working on these related projects:
All content following this page was uploaded by Bhaskar Mondal on 25 August 2016.
Contents
1 Fundamental of Computer 1
4 Basics of C Programming 6
9 Advanced Assignments 13
10 Books to Follow 13
Instructions
• Maintain your Lab Record regularly.
• Practice all programs by your own. Copying the solution from others will be
penalized.
• Maintain Index/ content properly.
• Brief descriptions including algorithm used and flowchart of the work you did
for each exercise.
• Copies of the C programme you written for the exercises, along with the results.
• You must provide Test Cases/sample Input and Output at the end of exercise.
• Explanations of anything unusual or interesting, or points of confusion that you
were unable to resolve outside lab.
• If you believe I have an error in a lab, please inform me of it. Explain why you
think it is an error and, if you like, suggest a correction.
• Save the C program files in a separate folder on PC (in Lab), also take your
respective C program files with yourself in Pen-Drive.
1 Fundamental of Computer
$ whereis gcc
$ which gcc
$ gcc --version
$
If gcc is not installed, if you are using Debian or Ubuntu Linux, type the following
apt-get command to install GNU c/c++ compiler:
Write your programme in any of the editors that are available under Linux such as
gedit, vi or emacs or any other editor. I like to use gedit, to use gedit open terminal and
type
gedit myfirstprog.c
It will create and open a file named myfirstprog.c for you where you can type your c
code. for example:
#include<stdio.h>
/* myfirstprog.c: My first C program on a Linux */
int main(void)
{
printf("Hello World \n");
return 0;
}
Preprocessor
Preprossed Code myprog.i
Compiler
Assembly Code myprog.s
Assembler
Object Code myprog.o
Library Files
Linker / Other object �les/
LinkEditor Modules
Executable Code myfprog.exe
Run time Objects,
Loader Module,
Library, etc.
Evaluate the
Problem
8 2
4
6
5
Take Identify
Action Solutions
Select Best
Solution
4 Basics of C Programming
tion.
7. Write a program to convert degrees Fahrenheit into degrees Celsius.
8. Write a program that displays the size of every data type.
9. The distance between two cities(in KM) is input through the keyboard. Write a
program to convert and print this distance in meters, feet, inches and centimeters.
10. The length and breadth of a rectangle and radius of a circle are input through the
keyboard. Write a program to calculate the area & perimeter of the rectangle, and
the area & circumference of the circle.
11. If a five-digit number is input through the keyboard, write a program to print a
new number by adding one to each of its digits. For example, if the number that
is input is 12391, then the output should be displayed as 23502.
12. Write a program to calculate the euclidean distance between two points. [hint:
include math.h, use sqrt() & pow() functions]
13. Write a program to calculate the bill amount for an item given its quantity sold,
value, discount and tax.
14. Write a program to convert a floating point number into corresponding integer.
15. Write a program to convert an integer into the corresponding floating point num-
ber.
16. Write a program to calculate a student’s result based on two examinations, one
sport event, and three activities conducted. The Weightage of activities = 30%,
sports = 20%, and examination = 50%.
17. In a town, the percentage of men is 52. The percentage of total literacy is
18. If total percentage of literate men is 35 of the total population, write a program to
find the total number of illiterate men and women if the population of the town is
80,000.
19. Write a program to enter an integer number and display its equivalent values in
binary, octal and hexadecimal.
9. If the three sides of a triangle are entered through the keyboard, write a program
to check whether the triangle is valid or not. The triangle is valid if the sum of
two sides is greater than the largest of the three sides.
10. If the three sides of a triangle are entered through the keyboard, write a program to
check whether the triangle isosceles, equilateral, scalene or right angled triangle.
11. In a company, worker efficiency is determined on the basis of the time required for
a worker to complete a particular job. If the time taken by the worker is between
2-3 hours, then the worker is said to be highly efficient. If the time required by
the worker is between 3-4 hours, then the worker is ordered to improve speed. If
the time taken is between 4-5 hours, the worker is given training to improve his
speed, and if the time taken by the worker is more than 5 hours, then the worker
has to leave the company. If the time taken by the worker is input through the
keyboard, write a program to find the efficiency of the worker.
12. Any character is entered through the keyboard, write a program to determine
whether the character entered is a capital letter, a small case letter, a digit or a
special symbol. The following table shows the range of ASCII values for various
characters.
Table 2
13. According to the Gregorian calendar, it was Monday on the date 01 January 2001.
If any year is input through the keyboard write a program to find out what is the
day on 1st January of this year.
14. A five digit number is entered through the keyboard. Write a program to obtain
the reversed number and to determine whether the original and reversed numbers
are equal or not.
15. A certain grade of steel is graded according to the following conditions:
(a) Hardness must be greater than 50
(b) Carbon content must be less than 0.7
(c) Tensile strength must be greater than 5600
The grades are as follows:
(a) Grade is 10 if all the three conditions are met
(b) Grade is 9 if conditions (i) and (ii) are met
(c) Grade is 8 if conditions (ii) and (iii) are met
(d) Grade is 7 if conditions (i) and (iii) are met
(e) Grade is 6 if only one condition is met
(f) Grade is 5 if none of the conditions are met
Write a program, which will require the user to give values of hardness, carbon
content and tensile strength of the steel under considerations and output the grade
of the steel.
16. The policy followed by company to process customer orders is given by the fol-
lowing rules:
(a) If a customer ordered quantity is less than or equal to that in stock and his
credit is OK, supply his requirement.
(b) If his credit is not OK do not supply. Send him intimation.
(c) If his credit is OK but the item in stock is less than his order, supply what is
in stock. Intimate to him the date on which the balance will be shipped.
Write a C program to implement the company policy.
17. Given three points (x1, y1), (x2, y2)and(x3, y3), write a program to check if all
the three points fall on one straight line.
18. Given the coordinates (x,y) of a center of a circle and it’s radius, write a program
which will determine whether a point lies inside the circle, on the circle or outside
the circle.
19. Given a point (x, y), write a program to find out if it lies on the x-axis, y-axis or
on the origin, viz (0, 0).
20. Write a program to calculate energy bill. Read the starting and ending meter
readings. The charges are as follows:
A B C D E F G F E D C B A
A B C D E F F E D C B A
A B C D E E D C B A
A B C D D C B A
A B C C B A
A B B A
A A
Table 3: pattern
1
2 3
4 5 6
7 8 9 10
Table 4: pattern
• If the student gets third class and the number of subjects he failed in is
greater than 1, then he does not get any grace. If the number of subjects he
failed in is equal to 1, then the grace is of 5 marks per subject.
7. Write a recursive function to obtain the first 25 numbers of a Fibonacci sequence.
In a Fibonacci sequence the sum of two successive terms gives the third term. Fol-
lowing are the first few terms of the Fibonacci sequence: 1, 1, 2, 3, 5, 8, 13, 21, 34 . . .
8. Write a function to compute the distance between two points and use it to develop
another function that will compute the area of the triangle whose vertices are
A(x1 , y1 ), B(x2 , y2 ), andC(x3 , y3 ). Use these functions to develop a function
which returns a value 1 if the point (x,y) lines inside the triangle ABC, otherwise
a value 0.
9. Write a function to compute the greatest common divisor given by Euclid’s algo-
rithm, exemplified for J = 1980, K = 1617 as follows:
1980 / 1617 = 1 1980 – 1 * 1617 = 363
1617 / 363 = 4 1617 – 4 * 363 = 165
363 / 165 = 2 363 – 2 * 165 = 33
5 / 33 = 5 165 – 5 * 33 = 0
Thus, the greatest common divisor is 33.
10. Write a function that will calculate and display the real roots of the quadratic
equation 3
ax2 + bx + c = 0 (3)
using the quadratic formula in 4
√
−b ± b2 − 4ac
x= (4)
2ac
Assume that a, b and c are floating-point arguments whose values are given, and
that x1 and x2 are floating-point variables. Also, assumes that b2 > 4 × a × c, so
that the calculated roots will always be real.
Now write a complete C program that will calculate the real roots of the quadratic
equation ax2 + bx + c = 0 using the quadratic formula, as described above. Read
the coefficient a, b and c in the main portion of the program. Then access the
function written for the preceding problem in order to obtain the desired solution.
Finally, display the values of the coefficients, followed by the calculated values
of x1 and x2 . Be sure that all of the output is clearly labeled.
11. A positive integer is entered through the keyboard, write a function to find the
binary equivalent of this number using recursion.
12. Following is the menu to be displayed to the user. On selecting a choice display
appropriate result. Number should be accepted from the user.
• Prime Factors
• Leap Year
• Sum of all digits
• Number in reverse order
13. Write macro definitions with arguments for calculation of Simple Interest and
Amount. Store these macro definitions in a file called “interest.h”. Include this
file in your program, and use the macro definitions for calculating simple interest
and amount.
14. Write down macro definitions for the following:
• To find arithmetic mean of two numbers.
• To find absoloute value of a number.
• To convert a uppercase alphabet to lowercase.
• To obtain the bigger of two numbers.
elements of the given arrays at the same index. Assume the arrays are of equal
length. Further Write a complete program to use this method.
11. Write a method that takes as its parameters two arrays of integers and returns
a new array where the value at each index is the sum of the corresponding two
elements of the given arrays at the same index. Do not assume the arrays are of
equal length. Pretend that the shorter array is padded with zeros at the end. (For
example, if the arrays are of length 3 and 5, your result should be as if the shorter
array had zeros in the "missing" slots.) Further Write a complete program to use
this method.
12. Write a method that takes as its parameter an array a of integers and modifies the
given array so that it contains a running sum of its original values. For example, if
the array originally had the values [3 2 4 7], after running your method that array
would instead contain [3 5 9 16], and if you ran it another time on the same array,
you’d have [3 8 17 33]. Further Write a complete program to use this method.
13. Write a method that takes as its parameter an "two dimensional?" array a of in-
tegers and fills the main diagonal with the value 1. (The main diagonal consists
of those entries whose row and column index are equal.) Assume the two dimen-
tional array is square. Further Write a complete program to use this method.
14. Write a method that takes an integer parameter n. It should create and return an
array of n arrays of integers, where the array for row 0 has length 0, the array
for row 1 has length 1, the array for row 2 has length 2, etc. All values in the
arrays can remain uninitialized (0). Further Write a complete program to use this
method.
15. Write a method that takes an array of String objects and returns a single String
that results from concatenating all the strings together, separated by spaces. Do
not add a space after the last element, nor before the first one. Further Write a
complete program to use this method.
name, price of the book, and flag indicating whether book is issued or not
5. Create a structure to specify data on students given below: Roll number, Name,
Department, Course, Year of joining. Assuming that there are not more than 100
students in the college.
(a) Write a function to print names of all students who joined in a particular
year.
(b) Write a function to print the data of a student whose roll number is given.
6. Write a program that compares two given dates. To store a date use a structure
that contains three members namely date, month and year. If the dates are equal
then display message as “Equal” otherwise “Unequal”.
7. Write a program to read a file and display its contents along with line numbers
before each line.
8. Rewrite Program no. 5 (above) using suitable File operations.
9. Suppose a file contains student’s record with each record containing name and age
of a student. Write a program to read these records and display them in sorted
order by name.
9 Advanced Assignments
will added soon.
10 Books to Follow
1 Let Us C, Author: Yashavant Kanetkar, Publisher BPB Publications, 2002 ISBN
8176566217, 9788176566216, Online:
https://https://books.google.co.in/books/about/LetU sC .html?id = 6XrjAAAACAAJ
2 Title Programming in ANSI C, Balagurusamy, Publisher: Tata McGraw-Hill Educa-
tion, 2008, ISBN 0070648220, 9780070648227, Online:https://https://books.google.co.in/books/
AokcsKn − 1iIC
3 Schaum’s Outline of Programming with C, Byron Gottfried, Edition 2, illustrated
Publisher McGraw-Hill Education, 1996, ISBN 0070240353, 9780070240353
Evaluation Scheme
EC Evaluation Data & Nature of
Duration Weightage
No. Component Time Component