Long Q/A Input and Output Handling - Students Free Notes

Write a program that takes input from the user for marks of five subjects, calculates the percentage, and prints the grade based on the following criteria: 90% and above: A+ 80%-89%: A 70%-79%: B 60%-69%: C Below 60%: Fail

#include <stdio.h> int main() { float marks[5], total = 0, percentage; char grade; // Taking input for marks printf(“Enter marks for five subjects:\n”); for (int i = 0; i < 5; i++) { printf(“Subject %d: “, i + 1); scanf(“%f”, &marks[i]); total += marks[i]; // Adding marks to total } // Calculating percentage percentage = … Read more

Explain different types of format specifiers used in C with examples.

In C, format specifiers are used with functions like printf() and scanf() to control the input and output format of variables. Below are some commonly used format specifiers: %d or %i: Used for printing or reading integers. int num = 10; printf(“%d”, num); // Output: 10 %f: Used for printing or reading floating-point numbers (e.g., … Read more

Write a program to check whether a given number is even or odd using the modulus operator.

#include <stdio.h> int main() { int num; // Take input from the user printf(“Enter a number: “); scanf(“%d”, &num); // Check if the number is even or odd using modulus operator if (num % 2 == 0) { printf(“%d is even.\n”, num); } else { printf(“%d is odd.\n”, num); } return 0; } Explanation: The … Read more

Write a program that reads the length of one side of a cube and prints its volume.

#include <stdio.h> int main() { float side, volume; // Reading the length of one side of the cube printf(“Enter the length of one side of the cube: “); scanf(“%f”, &side); // Calculating volume volume = side * side * side; // Printing the volume printf(“Volume of the cube: %.2f\n”, volume); return 0; } Related Questions: … Read more

Write a program that reads the length and width of a rectangle and prints its area.

#include <stdio.h> int main() { float length, width, area; // Reading length and width of the rectangle printf(“Enter the length and width of the rectangle: “); scanf(“%f %f”, &length, &width); // Calculating area area = length * width; // Printing the area printf(“Area of the rectangle: %.2f\n”, area); return 0; } Related Questions: Describe how … Read more

Write a program that reads temperature in Celsius, converts it into Fahrenheit, and prints it on the screen.

#include <stdio.h> int main() { float celsius, fahrenheit; // Reading temperature in Celsius printf(“Enter temperature in Celsius: “); scanf(“%f”, &celsius); // Converting Celsius to Fahrenheit fahrenheit = (celsius * 9 / 5) + 32; // Printing the temperature in Fahrenheit printf(“Temperature in Fahrenheit: %.2f\n”, fahrenheit); return 0; } These programs demonstrate basic operations like reading … Read more

Write a program that reads three numbers and prints their sum, product, and average.

#include <stdio.h> int main() { float num1, num2, num3, sum, product, average; // Reading three numbers printf(“Enter three numbers: “); scanf(“%f %f %f”, &num1, &num2, &num3); // Calculating sum, product, and average sum = num1 + num2 + num3; product = num1 * num2 * num3; average = sum / 3; // Printing results printf(“Sum: … Read more

Describe the functions of the following operators:

Relational Operators Relational operators are used to compare two values and return a boolean result (true or false). These operators compare the values based on the relationship between them. Here are the most common relational operators: ==: Equality operator. Returns true if both operands are equal. a == b // returns true if a equals … Read more

Describe how basic and compound assignment operators are used.

In programming, assignment operators are used to assign values to variables. Basic and compound assignment operators are two types of these operators. Basic Assignment Operator (=) The basic assignment operator is represented by the single equal sign (=). It assigns the value of the expression on its right-hand side to the variable on the left-hand … Read more