0% found this document useful (0 votes)
15 views2 pages

C Programs for Basic Computations

Uploaded by

saccoubaye.16
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)
15 views2 pages

C Programs for Basic Computations

Uploaded by

saccoubaye.16
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

C Programming Lab

Write an algorithm and C program to solve simple computational problems using arithmetic
expressions and the use of each operator leading to the simulation of a commercial calculator
(add, sub, multiply, division and modulus). (No built-in math function).

Write an algorithm and C program to compute the roots of a quadratic equation by accepting the
coefficients. Print appropriate messages.

Write an algorithm and C program


(i) To find the reverse of a positive integer and check for palindrome or not Display
appropriate messages.
(ii) To find the square root of a given number N and execute for all possible inputs with
appropriate messages. Note: Don’t use library function sqrt(n)

Write an algorithm and C program for 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 changed 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.

Write an algorithm and C program


(i) Using pointers to compute the sum and standard deviation of all elements stored in an
array of n real numbers.
(ii) To list the leap years from 1998 to 2025 and count number of leap years in this
period.
Write an algorithm and C program to implement Recursive functions for binary to Decimal
Conversion

Write an algorithm and C program to conduct the annual examination for 10 students for five
subjects. Write a program to read the data and determine the following:
(i) Total marks obtained by each student.
(ii) The highest marks in each subject and the name of the student who secured it.
(iii) The student who obtained the highest total marks.

Write an algorithm and C program to generate a bill that gives his total purchase amount,
discount amount and the savings amount for a company manufactures three products namely
fridge, smart TVs and washing machines. They give a discount of 10% on order for fridges if
the order is for Rs. 30,000 or more. The same discount of 10% is given on smart TVs orders of
value Rs. 40,000 or more and on washing machine orders for Rs. 35,000 or more. A dealer
purchases a few fridges, smart TVs and washing machines.

Write an algorithm and C program


(i) To read 10 numbers
(ii) To sort these 10 numbers in decendig order
(iii) To find a given number is present or not
(iv) To remove duplicate numbers

Write an algorithm and C program


(i) To print the first letter of each word.
(ii) To reverse a string using recursion

Common questions

Powered by AI

The C program should iterate from 1998 to 2025 to identify leap years, which are determined by checking if a year is divisible by 4 but not by 100, unless divisible by 400. The output includes a list of leap years within the timeframe and a count of these leap years, showcasing the program's utility in such calendrical computations .

A C program can handle duplicate numbers through sorting and then iterating to compare adjacent elements to identify duplicates for removal. This approach is efficient, leveraging sorting algorithms like QuickSort or MergeSort followed by a single pass to eliminate duplicates, reducing overall processing efforts for large datasets .

Reversing a string using recursion in C involves swapping the first and last characters and recursively calling the function to reverse the substring between them until the base case is reached. This process exemplifies recursive logic by breaking down the problem and using the function stack, which aids in better understanding recursion's power and application .

In a C program, the electricity bill can be calculated by first determining the unit price based on consumption: 80 paise per unit for the first 200 units, 90 paise per unit for the next 100 units, and Rs 1 per unit beyond 300 units. Additionally, a minimum charge of Rs 100 as a meter charge is added to all bills. If the total amount exceeds Rs 400, a surcharge of 15% of the total amount is applied. The program must read the user's name and number of units consumed, compute charges accordingly, and include the surcharge conditionally .

Calculating roots of quadratic equations in C without built-in functions involves using the standard quadratic formula: (-b ± sqrt(b^2 - 4ac)) / 2a. Since sqrt() is unavailable, a custom function using approximation methods like Newton's Method or binary search must substitute. This method demonstrates understanding of both mathematical concepts and iterative approximation for solving complex equations .

Reversing a positive integer involves iterative division and remainder operations to extract digits, facilitating tasks like data validation or cryptographic variations. Checking for a palindrome (where the integer reads the same forwards and backwards) further verifies data integrity or serves as a mathematical check, with applications in number theory .

Recursive functions in C can be used for converting binary numbers to decimal by systematically reducing the size of the problem at each recursive call. The function can take parameters like the binary number and its current index, converting one digit at a time from rightmost to leftmost, multiplying each by 2 raised to the index's power, and summing these values. Recursion simplifies the code, making it easier to understand and maintain while efficiently handling large numbers through its systematic breakdown .

Conducting annual examinations in C programming involves reading data for 10 students over five subjects, calculating total marks for each, identifying highest marks in each subject along with the student name, and determining the top overall student based on total marks. This process requires efficient data structuring and looping mechanisms for calculations, promoting fair assessment and providing insights into academic excellence .

To compute the standard deviation using pointers in a C program, one must first calculate the mean of the numbers, sum the squared differences from the mean, divide by the number of elements for variance, and take the square root. Using pointers allows for efficient indirect array access and manipulation, reduces memory use by avoiding array copies, and facilitates the management of dynamic memory, providing faster data processing .

In C programming, sorting numbers in descending order can be implemented using algorithms like Bubble Sort, QuickSort, or MergeSort. The choice of algorithm affects performance in terms of time complexity and memory usage. For instance, QuickSort offers O(n log n) complexity on average, suitable for efficient sorting of large datasets. However, considerations must include worst-case scenarios and stack space for recursive sorts .

You might also like