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

Differentiate between printf() and scanf() functions.

printf() is used to display output to the screen, whereas scanf() is used to take input from the user. printf() formats and outputs data, while scanf() reads and stores data from the user into variables.Example: int num; scanf(“%d”, &num); // User input is stored in ‘num’ printf(“You entered: %d”, num); // Output the value of … Read more