14CPL16 - Computer Programming Lab Manual (VTU PESIT) PDF
14CPL16 - Computer Programming Lab Manual (VTU PESIT) PDF
Laboratory Session-1: Write-up on Functional block diagram of Computer, CPU, Buses, Mother
Board, Chip sets, Operating System & types of OS, Basics of Networking & Topology and NIC.
Laboratory Session-2: Write-up on RAM, SDRAM, FLASH memory, Hard disks, Optical media,
CD-ROM/R/RW, DVDs, Flash drives, Keyboard, Mouse, Printers and Plotters.
Note: These TWO Laboratory sessions are used to fill the gap between theory classes and practical sessions.
http://www.c4learn.com/c-programs/category/file-programs
Problem Statement 1 :
Design and develop a flowchart or an algorithm that takes three coefficients (a, b, and c)
of a Quadratic equation (ax2+bx+c=0) as input and compute all possible roots. Implement
a C program for the developed flowchart/algorithm and execute the same to output the
possible roots for a given set of coefficients with appropriate messages.
Objective:
To understand the decision making constructs and find the roots of a quadratic equation
Algorithm:
Step 7: Stop
Problem Statement 2 :
Design and develop an algorithm to find the reverse of an integer number NUM and
check whether it is PALINDROME or NOT. Implement a C program for the developed
algorithm that takes an integer number as input and output the reverse of the same
with suitable messages. Ex: Num: 2014, Reverse: 4102, Not a Palindrome
Objective:
To understand the while loop construct and find if a given number is palindrome
Algorithm:
Step 6.[finished]
Stop
Problem Statement 3:
3a. Design and develop a flowchart to find the square root of a given number N.
Implement a C program for the same and execute for all possible inputs with
appropriate messages. Note: Don’t use library function sqrt(n).
Objective:
To understand the while loop construct and find square root of a given number.
Algorithm:
Step 5.STOP
Squareroot(LG,NG,n)
Step 1.[Loop]
do{
NG=(0.5*(LG+n/LG));
LG=NG;
}while((NG*NG-n)<0.005;
Objective:
Algorithm:
Design and develop an algorithm for evaluating the polynomial f(x) = a4x4 + a3x3 + a2x2
+ a1x + a0, for a given value of x and its coefficients using Horner’s method.
Implement a C program for the developed algorithm and execute for different sets of values of
coefficients and x.
Objective:
Algorithm:
Step 1.[input n]
Read n
Step 4. [initialize]
product=a[n]*x
Step 7.[finished]
Stop
Problem Statement 5 :
Objective:
Algorithm:
Step 4:Stop
Factorial(n)
Step 1:if(n==0 || n==1)
Return 1
Else
Return(n*factorial(n-1)
Step 2 :Stop
Problem Statement 6:
Develop, implement and execute a C program that reads N integer numbers and arrange
them in ascending order using Bubble Sort technique. Extend the program to perform a
search operation on these sorted numbers by accepting a key element from the user applying
Binary Search method. Report the result SUCCESS or FAILURE as the case may be.
Objective:
To understand technique using bubble sort and working of binary search and search
for a given key integer in an array.
Algorithm:
Objective:
Algorithm:
Step 8.[Finished]
Stop
Problem Statement 8 :
Algorithm:
Step 4. Stop
ii. Reads a sentence and prints frequency of each of the vowels and total count of
consonants
Objective:
Algorithm:
Step 4.Stop
Problem Statement 9 :
a. Design and develop a C function RightShift(x ,n) that takes two integers x and n
as input and returns value of the integer x rotated to the right by n positions. Assume
the integers are unsigned. Write a C program that invokes this function with different
values for x and n and tabulate the results with suitable headings.
Objective:
Algorithm
Step1: [Read the number and the number of bits to be shifted] read x,
n
Step4: [finished]
stop
rightrot(int x, int n)
Step 1: [right shift x by n bit positions]
for i=0 to n1-1 in step1
if x%2 then
x1=x1>>1
x1+=1<<15
else
x1=x1>>1
end if
Objective:
To understand the concept of functions and check if a given number is prime or not
Algorithm:
Step 3: if ans == 0
Print “the number is not prime”
else
Print “the number is prime”
Step 5: if ch==1
goto step 1
else
goto step 6
end if
Step 6: Stop
isprime(n) function
Develop a function in C called MatchAny(s1,s2) that takes two string arguments and
does the following task:
i) if s1 is substring of s2, Returns 1 along with the first location in the string s2,
ii) if s1 is equal to s2 , returns 0 and
iii) otherwise, returns -1.
Write a C program that invokes MatchAny(s1,s2) for different input strings and output
both the strings s1 & s2 with the return value in tabular form. Note: Do not use the
standard library functions
Objective:
To develop a matchany(a,b) function in C that takes two string parameters and to
understand how the string manipulations are done.
Algorithm:
Main() funtion
Step 3: if found==-1
print”no match found”
else
print the character and the position
end if
Step 4: [Get the choice from the user to continue]
read ch
Step 5: if ch==1
goto step1
else
goto step6
end if
Step 6: stop
Match(a,b) function
Step 1: for i=0 to end of string a in step 1
for j=0 to end of string b in step 1
if a[i]=b[j]
return i
end if
end for
end for
Step 2: return -1
Problem Statement 11 :
Draw the flowchart and write a recursive C function to find the factorial of a number,
n!, defined by fact(n)=1, if n=0. Otherwise fact(n)=n*fact(n-1). Using this function,
write a C program to compute the binomial coefficient nCr. Tabulate the results for
different values of n and r with suitable messages.
Objective:
Algorithm
Step 5.Stop
factorial(n)
Step 1.if (n = 0)
return 1;
Problem Statement 12 :
Given two text documentary files “Ramayana.in” and “Mahabharatha.in”. Write a C
program to create a new file “Karnataka.in” that appends the content of file
“Ramayana.in” to the file “Mahabharatha.in”. Display the contents of output file
“Karnataka.in” on to screen. Also find number of words and newlines in the output file.
Objective:
Algorithm
Write a C program to maintain a record of “n” student details using an array of structures
with four fields (Roll number, Name, Marks, and Grade). Each field is of an appropriate
data type. Print the marks of the student given student name as input.
Objective:
Algorithm:
step 7.Stop
Problem Statement 14:
14. a. Write a C program using pointers to compute the sum of all elements stored in an array
A[n]. Where n is the number of elements.
Objective:
Algorithm:
Step 6.Stop
b. Write a C program to find sum of n elements entered by the user. Demonstrate the
program using functions malloc() to allocate memory dynamically and free() to
deallocate.
Objective:
Algorithm:
For(i=0 to n-1)
Input to a[i]
End for
Step 5. Free(ptr)
Step 6.Stop
Problem Statement 15:
Objective:
Step 4.
arraySort(numPtr, numStudents);
if(numStudents % 2 == 0)
{
median = (*(numPtr + (numStudents / 2)) - 1) + *(numPtr + (numStudents / 2));
median /= 2;
}
Else
{
median = *(numPtr + (numStudents / 2));
}
return median;
}