0% found this document useful (0 votes)
58 views9 pages

IT18111 Lab Plan Detailed

The document provides exercises on Linux commands, C programming, and problem solving using arrays and control structures. It includes tasks such as creating directories and files using Linux commands, writing C programs to perform calculations and accept user input, solving problems using decision making and loops, and working with one and two dimensional arrays. The exercises cover a range of fundamental programming concepts and are designed to help students learn and practice programming for problem solving.

Uploaded by

Surya SJ
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)
58 views9 pages

IT18111 Lab Plan Detailed

The document provides exercises on Linux commands, C programming, and problem solving using arrays and control structures. It includes tasks such as creating directories and files using Linux commands, writing C programs to perform calculations and accept user input, solving problems using decision making and loops, and working with one and two dimensional arrays. The exercises cover a range of fundamental programming concepts and are designed to help students learn and practice programming for problem solving.

Uploaded by

Surya SJ
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/ 9

SRI VENKATESWARA COLLEGE OF ENGINEERING

Department of Information Technology


IT18111 Programming for Problem Solving Laboratory

EXERCISE 1

A. Linux Commands
i. Create directory
ii. Change directory
iii. Create file using “cat”
iv. Display the content of file
v. List the files in a directory
vi. Copy a file to another directory
vii. Move a file to another directory
viii. Rename a file
ix. Delete a file

B. Create a directory SVCE. Under SVCE directory, create sub directory for each
department and also create separate sections (A& B Sec) of those departments as sub directory
as given in the below figure. Under each section’s directory, create a file which contains name of
the students.

SVCE

IT CSE ECE EEE

A Sec B Sec A Sec B Sec A Sec B Sec A Sec B Sec

EXERCISE 2

C Programming using Simple statements and expressions

A. Write a C program to accept your roll no from the user as input and to display
“Welcome to Programming for Problem Solving lab with your roll no”. Roll No should
be printed in separate line

B. Write a C program to accept integer, float, character values and print the same in one
line separated with one tab space. Check how input will be accepted when format
specifier separated with comma and space in scanf(). Check the program works with
input [40,000] for integer variable.

C. Write a C program to convert time elapsed in seconds to hh:mm:ss format,where


hh,mm and ss are hours, minutes and seconds, respectively.
D. Write a printf function for accepting three integer variables i,j,k and produce the output
according to the following constraints

 i, j and k, with a minimum field width of three characters per quantity with left
justified with its respective field

 ( i + j ), ( i - k) ,with a minimum field width of five characters per quantity with


right justified.

 sqrt (i + j ), abs (i - k), with a minimum field width of nine characters for the
first quantity, and seven characters for the second quantity

Additional Programs

E. Given three numbers, assign the value of the first number to the second, the second
number to the third and the third number to the first using fourth variable and without
using fourth variable.

F. Write a c program using printf statement to print "BYE" using the character '*'.
**** * * ****
* * * * *
* ** * ****
* * * *
**** * ****

G. Given the coordinates (x, y) of the centre of a circle and its radius r, determine whether
point(x , y) lies inside it or not using ternary (conditional) operator.

H. To print the ASCII value of the given input character.

EXERCISE 3

Scientific problem solving using decision making.

a. The Jones Trucking Company tracks the location of each of its trucks on a grid similar to
an (x, y) plane. The home office is at location (0, 0). Read the coordinates of truck A and
the coordinates of truck B and determine which is closer to the office

b. Given the coordinates of the left –top corner(x1,y1) and right bottom corner of a rectangle,
determine whether it is a square or not.

c. Assign a value to double variable cost depending on the value of integer variable distance
as follows:
d. Write a switch statement that will examine the value of an integer variable called flag
and print one of the following messages, depending on the value assigned to flag.
(a) HOT, if flag has a value of 1
(b) LUKE WARM, if flag has a value of 2
(c) COLD, if flag has a value of 3
(d) OUT OF RANGE if flag has any other value

e. Consider the following characters : (,{,[,<. Accept one of these characters and print the
name of the corresponding characters as Parentheses, Curly braces, Square brackets and
Angle brackets using switch statements.

Additional Programs

f. Chootu wants to calculate electricity bill according to the given condition:


For first 50 units Rs. 0.50/unit
For next 100 units Rs. 0.75/unit
For next 100 units Rs. 1.20/unit
For unit above 250 Rs. 1.50/unit
An additional surcharge of 20% is added to the bill. Input:electricity unit charges

g. A company decides to give bonus to all its employees on Diwali. A 5% bonus on salary is
given to the male workers and 10% bonus on salary to the female workers. Write a program to
enter the salary and sex of the employee. If the salary of the employee is less than rs. 10,000 then
the employee gets an extra 2% bonus on salary. Calculate the bonus that has to be given to the
employee and display the salary that the employee will get.

h. Write an appropriate control structure that will examine the value of a floating-point variable
called temp and print one of the following messages, depending on the value assigned to temp.
ICE, if the value of temp is less than 0.
WATER, if the value of temp lies between 0and 100.
STEAM, if the value of temp exceeds 100.
Can a switch statement be used in this instance?

i. Write a switch statement that will examine the value of a char-type variable called color and
print one of the following messages, depending on the character assigned to color.
(a) RED, if either r or R is assigned to color,
(b) GREEN, if either g or G is assigned to color,
(c) BLUE, if either b or B is assigned to color,
(d) BLACK, if color is assigned any other character.
EXERCISE 4

Scientific problem solving using looping

a. Write a program to print the count of even numbers between 1 and 200. Also print the
sum. Use do while loop

b. Write a program that reads in an integer value for n and then sums the integers from n
to 2*n if n is nonnegative or from 2 * n to n if n is negative. Write the code in two
versions,one using for loops and the other using only while loops.

c. A Krishnamurthy number is a number whose sum of the factorial of digits is equal to


the number itself. Given a number N as input. Write a program to check whether this
number is krishnamurthy number or not

d. Print the multiplication table according to the inputs (N, limit) . Test the program for
the inputs as given below N=6, limit=10

6*1=6,
6*2=12
.
.
.
.
6*10=60
e. Print following patterns
1
22
333
4444
5 5 5 5 5_

Additional Programs

h . Arrange 15 asteriks in the shape of a equilateral triangle.

i. Write an interactive program that will read in a positive integer value and determine the following:
(i) If the given integer is divisible by one and divisible by itself but not divisible by other number .
(ii) If the integer is a Armstrong number such that 1634 = 14+64+34+44 and 3= 31
Write the program in such a manner that it will execute repeatedly, until a zero value is detected for
the input quantity. Test the program with several integer values of your choice.

j. The Fibonacci numbers are members of an interesting sequence in which each number is equal to
the sum of the previous two numbers. In other words,

Fi = Fi-1 + Fi-2

where Fi refers to the ith Fibonacci number. By definition, the first two Fibonacci numbers equal 1;
i.e.,
Fi=F2=1.
Hence,
F3 = F2 + F1 = 1 + 1 = 2
F4 = F3 + F2 = 2 + 1 = 3
Fs = F4 + F3 =3 + 2= 5
and so on.
Write a program that will determine the first n Fibonacci numbers. Test the program with n = 7, n =
10,n= 17andn=23

EXERCISE 5

Simple programming for one dimensional and two dimensional arrays.

a. Write a program to print the sum of odd numbers and sum of even numbers separately in the given
array.

b. Write a program to accept the marks secured in CAT by the students for the subject PPS. Find out
the student who has got the highest marks in your class

c. User inputs a number and then enters aseries of numbers from 1 to N. Determine which number is
missing or duplicated in the series. For example, if the user entered 10as the value of N. The results
should be as shown

Input sequence Output


1 2 4 7 4 4 5 10 8 2 6 Duplicate 2
Missing 3
Duplicate 4
Missing 9

d. Write a program to accept a 2D matrix and double the values present in the diagonal elements.

Additional Programs

d. Write a program to read marks of 10 students in the range of 0 - 100. Then make 10 groups: 0-
10,11-20,21-30,... Count the number of values that falls in each group and display the result.

e. A class of students earned the following grades for the six examinations taken in a C programming
course.
Name ExamScoresI-1
Adams 45 80 80 95 55 75
Brown 60 50 70 75 55 80
Davis 40 30 10 45 60 55
Fisher 0 5 5 0 10 5
Hamilton 90 85 100 95 90 90
Jones 95 90 80 95 85 80
Ludwig 35 50 55 65 45 70
Osborne 75 60 75 60 70 80
Prince 85 75 60 85 90 100
Richards 50 60 50 35 65 70
Smith 70 60 75 70 55 75
Thomas 10 25 35 20 30 10
Wolfe 25 40 65 75 85 95
Zorba 65 80 70 100 60 95
Write an interactive C program that will accept each student’s name and exam grades as input,
determine an average grade for each student, and then display the student’s name, the individual exam
grades and the calculated average.

g. Suppose we are given a table of integers, A, having m rows and n columns, and a list of integers, X,
having n elements. We wish to generate a new list of integers, Y, that is formed by carrying out the
following
operations.
Y[1] = A[l][l]*X[l] + A[l][2]*X[2] + . . . + A[l][n]*X[n]
Y[2] = A[2][1]*X[l] + A[2][2]*X[2] + . . . + A[2][n]*X[n]
Y[m] = A[m][l]*X[l] + A[m][2]*X[2] + . . . + A[m][n]*X[n]

EXERCISE 6

Solving problems using Strings

a. Write a C program to count the number of times the given character X present in the given
string.

b. Write a C program to accept the string and reverse all the characters in the given string. Check
whether the reversed string is same as the original string.

c. Write program to print the string in the following pattern


h
he
hel
hell
hello
hello
hell
hel
he
h

Additional Programs

a. In this challenge, you will determine whether a string is funny or not. To determine whether a
string is funny, create a copy of the string in reverse abc->cba. Iterating through each string,
compare the absolute difference in the ascii values of the characters at positions 0 and 1, 1 and
2 and so on to the end. If the list of absolute differences is the same for both strings, they are
funny.

Determine whether a give string is funny. If it is, return Funny, otherwise return Not Funny.For
example, given the string s=lmnop the ordinal values of the charcters are
[108,109,110,111,112]. Reversed string=ponml and the ordinals are [112,111,110,109,108].
The absolute differences of the adjacent elements for both strings are [1,1,1,1]. So, the answer
is Funny.

b. Write a program to read a short story to display the n lines of story starting from mth line.
EXERCISE 7

C Programming using user defined functions (Pass by value and Pass by reference)

a. Write a program to find sum of digits of a number until sum becomes single digit.

b. Write a function that will allow a floating-point number to be raised to an integer power. In other
words, we wish to evaluate the formula y=xn where y and x are floating-point variables and n is an
integer variable.

c. Write a C program to accept three numbers x , y, z .


 Write a function using call by value to swap x , y, z. Print the value of x, y and z within the
function and outside the function.
 Write a function using call by reference to swap x,y,z. Print the value of x, y and z within the
function and outside the function.

d. Write a C program to sort a given array of strings into lexicographically increasing order

Additional Programs

e. Write a C program to compute the series x+x2/2! +x3/3! +...

f. Suppose we want to read two tables of integers into the computer calculate the sums of the
corresponding elements, i.e., and then display the new table containing these sums. We will assume
that all of the tables contain the same number of rows and columns, not exceeding 20 rows and 30
columns using functions

EXERCISE 8

C Programming using Recursion

a. Write a C program to calculate the factorial of given number using recursion

b. Write a C program to compute sum of first N natural numbers using recursion

c. Write a C program to find the xy using recursion.

Additional Programs

d. Write a C program to compute Lambda(n) for all positive values of n where Lambda(n) can be
recursively defined as Lambda(n) = Lambda(n/2)+1 if n>1 and lambda (n)=0 if n=1.

e. Write a C program to calculate GCD of two numbers using recursion


EXERCISE 9

C Programming using structures and union

a. Write a program to print the tickets of the boarders of a boat using array of structures with
initialization in the program.

b. A railway ticket generation program.

c. Write a program that illustrates the initialization of a member in a union.

Additional Programs

d. Write a menu-based program in C that uses a set of functions to


perform the following operations:
 reading a complex number
 writing a complex number
 addition of two complex numbers
 subtraction of two complex numbers
 multiplication of two complex numbers
Represent the complex number using a structure.

e. Declare a structure to store the following information of an employee-


• Employee code
• Employee name
• Salary
• Department number
• Date of join(it is itself a structure consisting of day, month and year)

f. Write a C program to store the data of ‘n’ employees where n is given by the user (Use dynamic
memory allocation).Include a menu that will allow user to select any of the following features:

 Use a function to display the employee information getting the maximum and minimum salary.
 Use a function to display the employee records in ascending order according to their salary.
 Use a function to display the employee records in ascending order according to their date of
join.
 Use a function to display the department wise employee records.

EXERCISE 10

C Programming using Pointers

a. Declare a integer pointer variable, initialize and access the integer data through the pointer variable.

b. Swap three floating point numbers using pointers.

c. Write a program using pointer to structure illustrating the intilization of members in the structure.

d. Accept an array with 5 elements and display it using pointer variable.


EXERCISE 11

C Programming using Files

a. A program to illustrate to write a single character at a time into file.

b. Write a C program that accepts the names of two files. It should copy first file into the
second file line by line. use fgets() and fputs().

c. Write a C program that counts the number of characters and number of lines in a file.

EXERCISE 12

C Programming using enumerated data types.

EXERCISE 13

C Programming using macros and storage classes.

You might also like