Cha C Report 3&4
Cha C Report 3&4
ivision) on two float numbers using preprocessor directives for operators and to input and
d
display personal details (name, address, age, weight, height) using unformatted I/O.
Problem Analysis:
● A variable Ch1 to store the mathematical operator received from the user using
unformatted I/O.
PLUS, MINUS, MULTIPLY, and DIVIDE. These operators are then applied in the
c alculation of the result stored in the variable z. The operations are performed
based on the operator chosen by the user.
For personal details, we use unformatted I/O to get input for the following
variables: ● Name, address (as strings)
Algorithm:
1. Start
DIVIDE).
6. Receive input for the operator (Ch1) using unformatted I/O.
11.End
Flowchart :
ource Code :
S
#include <stdio.h>
int main() {
// Declare float variables for the numbers and for user input
float num1, num2;
char name[50];
int age;
// Addition
printf("Addition: %.2f + %.2f = %.2f\n", num1, num2, num1 + num2);
// Subtraction
printf("Subtraction: %.2f - %.2f = %.2f\n", num1, num2, num1 - num2);
// Multiplication
printf("Multiplication: %.2f * %.2f = %.2f\n", num1, num2, num1 * num2);
return 0;
}
subtraction, multiplication, and division) using preprocessor directives and unformatted I/O
for receiving the operator. The program also takes personal information using unformatted
I/O and displays the data. The unformatted I/O operations work as intended for string input,
although care should be taken to avoid buffer overflow issues when using gets().
Lab Report -4:
Title:Write a program to calculate and displaythe total marks, percentage, and rank for 5
subjects (Physics, Chemistry, Math, English, and Biology) based on the obtained marks.
Objectives:
o calculate the total marks, percentage, and display the rank of each subject and
T
the overall rank based on the given marks for 5 subjects.
Problem Analysis:
To solve the problem, we need to input the marks for 5 subjects (Physics, Chemistry, Math,
English, and Biology). The total marks and percentage will be calculated based on the input
marks, and the rank of each subject will be determined by categorising the marks into ranks
s uch as fail, pass, second division, first division, distinction, and extraordinary
based on the percentage ranges.
Algorithm:
1. Start
2. Declare variables to store the marks of 5 subjects, total marks, percentage,
and ranks for each subject.
3. Take input from the user for marks of Physics, Chemistry, Math, English, and Biology.
4. Calculate the total marks by summing the marks of all subjects.
6. Determine the rank for each subject based on the percentage:
7. Display the total marks, percentage, and the rank for each subject.
9. End
Flowchart :
ource Code :
S
#include <stdio.h>
int main() {
// Declare variables for marks and total
float physics, chemistry, math, english, biology;
float totalMarks, percentage;
char rank[20];
return 0;
}
Output (compilation, debugging & testing)
The refined C program effectively addresses the requirements by providing a structured and
maintainable codebase. The use of functions enhances readability and facilitates easier
debugging and future modifications. Input validation ensures that the program handles
unexpected or incorrect user inputs gracefully, preventing potential runtime errors.