0% found this document useful (0 votes)
23 views1 page

BPOPS103 C Programming Lab Manual

The document outlines a course on Principles of Programming Using C, identified by the code BPOPS103/203. It includes various programming tasks such as creating a simple calculator, computing quadratic roots, calculating electricity charges, implementing binary search, matrix multiplication, and string operations. Additional tasks involve using pointers for statistical calculations and file handling in C.
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)
23 views1 page

BPOPS103 C Programming Lab Manual

The document outlines a course on Principles of Programming Using C, identified by the code BPOPS103/203. It includes various programming tasks such as creating a simple calculator, computing quadratic roots, calculating electricity charges, implementing binary search, matrix multiplication, and string operations. Additional tasks involve using pointers for statistical calculations and file handling in C.
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

Course: Principles of Programming Using C

Code: BPOPS103/203

1. Simulation of a Simple Calculator.


2. Compute the roots of a quadratic equation by accepting the coefficients. Print
appropriate messages.
3. An electricity board charges the following rates for the use of electricity: for the first
200 units 80 paise per unit: for the next 100 units 90 paise per unit: beyond 300 units
Rs 1 per unit. All users are charged a minimum of Rs.100 as meter charge. If the total
amount is more than Rs 400, then an additional surcharge of 15% of total amount is
charged. Write a program to read the name of the user, number of units consumed and
print out the charges.
4. Write a C Program to display the following by reading the number of rows as input,

121

12321

1234321

---------------------------

nth row

5. Implement Binary Search on Integers


6. Implement Matrix multiplication and validate the rules of multiplication.
7. Compute sin(x)/cos(x) using Taylor series approximation. Compare your result with the
built-in library function. Print both the results with appropriate inferences.
8. Sort the given set of N numbers using Bubble sort.
9. Write functions to implement string operations such as compare, concatenate, and find
string length. Use the parameter passing techniques.
10. Implement structures to read, write and compute average- marks of the students, list the
students scoring above and below the average marks for a class of N students.
11. Develop a program using pointers to compute the sum, mean and standard deviation
of all elements stored in an array of N real numbers.
12. Write a C program to copy a text file to another, read both the input file name and target
file name.

Common questions

Powered by AI

A C program manages file copying by using file pointers to open, read, and write to files. It begins by reading both input and target file names via user input. 'fopen' is used to open files, and error checking ensures files open successfully. Inside a loop, 'fgetc' reads from the source file and 'fputc' writes to the target file until EOF is reached. Finally, files are closed with 'fclose' to free memory resources. Error handling assures robustness by verifying file accessibility and ensuring correct operation .

Structures in C provide a means to organize related data items, such as student information, into a single unit for streamlined management. In managing student data for average mark computation, structures store attributes like student names and marks, simplifying data manipulation and access. By encapsulating data, structures enable organized processing, facilitate functions to act on combined data sets, and improve code readability and maintenance .

Implementing matrix multiplication in C involves iterating over two matrices and calculating the dot product for each resulting element. The number of columns of the first matrix must equal the number of rows of the second matrix to validate the multiplication rule. Nested loops iterate through matrix dimensions to sum products of corresponding elements. The result is stored in a new matrix. The program requires careful indexing to avoid errors and respect matrix size constraints .

Bubble sort involves repeatedly passing through a list of numbers, comparing adjacent elements and swapping them if they are in the wrong order. This process repeats until the entire list is sorted. Implementation in C uses nested loops: the outer loop tracks the pass number and the inner loop performs comparisons and swaps. The efficiency of this sorting algorithm is best for small data sets due to its O(n^2) complexity .

To perform a binary search on a sorted array, the algorithm begins by setting two indices: 'low' to the first element and 'high' to the last. It calculates the mid-point and compares if the target value matches the middle element. If not, it adjusts 'low' or 'high' depending on whether the target is less or greater than the middle element. This process repeats until the target is found or the indices converge, signifying the element is not present. This method ensures efficient searching with O(log n) time complexity .

To approximate sin(x)/cos(x) using Taylor series, the program expands both sin(x) and cos(x) individually using their respective series: sin(x) = x - x^3/3! + x^5/5! ... and cos(x) = 1 - x^2/2! + x^4/4!... Calculating their ratios gives an approximation for tan(x). This result is then compared with the output from C's library function for tan(x), and both results are printed alongside inferences on their accuracy under various input conditions .

A C program can classify student grades by first calculating the average grade of the class. It sums all grades and divides by the number of students. Using structures, each student's data is stored, and their grades are iterated. Students with grades higher than the average are listed as above average, and others as below. This approach uses conditional statements within a loop to distinguish the students based on their performance relative to the computed average .

A C program can perform string operations using functions that take character arrays as parameters. For string comparison, a function iteratively compares each character until a difference is found or the end is reached. Concatenation involves copying one string into another starting at the null terminator of the first. Calculating string length counts characters until the null terminator is reached. Parameter passing is done using pointers to manipulate string data directly and efficiently .

To calculate electricity charges, the program first determines the number of units consumed. It applies specific rates: 80 paise per unit for the first 200 units, 90 paise for the next 100, and Rs 1 per unit beyond 300 units. A minimum meter charge of Rs 100 is always applied. If the total charges exceed Rs 400, an extra 15% surcharge is added. The program also requires inputs like the user's name and units consumed to print the total bill .

Pointers enhance statistical computations by allowing direct memory access and manipulation, improving efficiency. To compute the sum, mean, and standard deviation, a pointer is used to traverse the array. Sum is calculated by iterating through the array using a pointer to access each element. Mean is found by dividing the sum by the number of elements. For standard deviation, each element's deviation from the mean is squared and averaged. Using pointers eliminates the need for additional indexing variables, streamlining the program .

You might also like