KEMBAR78
Chapter 11 Exercise Programs | PDF | Number Theory | Computer Science
0% found this document useful (0 votes)
16 views3 pages

Chapter 11 Exercise Programs

The document contains solved programs for various exercises, including calculating the area of a square or triangle, checking for leap years, displaying messages based on temperature, calculating percentage and grades, and performing arithmetic operations based on user choices. Each program is written in C and prompts the user for input to execute the respective functionality. The code snippets demonstrate basic programming concepts such as conditionals, loops, and user input handling.

Uploaded by

hwf8vdqbgz
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)
16 views3 pages

Chapter 11 Exercise Programs

The document contains solved programs for various exercises, including calculating the area of a square or triangle, checking for leap years, displaying messages based on temperature, calculating percentage and grades, and performing arithmetic operations based on user choices. Each program is written in C and prompts the user for input to execute the respective functionality. The code snippets demonstrate basic programming concepts such as conditionals, loops, and user input handling.

Uploaded by

hwf8vdqbgz
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
You are on page 1/ 3

Chapter 11 Exercise Solved Programs

Question 8: write a program that Compute the area of a square or a triangle ( Ask user to enter S for
square and T for Triangle)
#include <stdio.h>
int main() {
char figureType;
printf("Enter the first character of the figure name (S or T): ");
scanf(" %c", &figureType);

if (figureType == 'S' || figureType == 's') {


float side, area;
printf("Enter the side length of the square: ");
scanf("%f", &side);
area = side * side;
printf("Area of the square: %f\n", area);
} else if (figureType == 'T' || figureType == 't') {
float base, height, area;
printf("Enter the base length of the triangle: ");
scanf("%f", &base);
printf("Enter the height of the triangle: ");
scanf("%f", &height);
area = 0.5 * base * height;
printf("Area of the triangle: %f\n", area);
} else {
printf("Invalid figure type.\n");
}

// Question 9: Check if a year is a leap year


#include <stdio.h>
int main() {
int year;
printf("\nEnter a year: ");
scanf("%d", &year);

if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {


printf("Leap year\n");
} else {
printf("Not a leap year\n");
}
}
// Question 10: Display a message based on temperature
#include <stdio.h>
int main() {
float temperature;
printf("\nEnter temperature: ");
scanf("%f", &temperature);

if (temperature > 35) {


printf("Hot day\n");
} else if (temperature >= 25 && temperature <= 35) {
printf("Pleasant day\n");
} else {
printf("Cool day\n");
}
}

// Question 11: Calculate percentage and display grade


#include <stdio.h>
int main() {
int obtainedMarks;
printf("\nEnter obtained marks (out of 1100): ");
scanf("%d", &obtainedMarks);

float percentage = (float)obtainedMarks / 1100 * 100;

if (percentage >= 80) {


printf("Grade: A+\n");
} else if (percentage >= 70) {
printf("Grade: A\n");
} else if (percentage >= 60) {
printf("Grade: B\n");
} else if (percentage >= 50) {
printf("Grade: C\n");
} else if (percentage >= 40) {
printf("Grade: D\n");
} else {
printf("Grade: F\n");
}
}
// Question 12: Perform arithmetic operation based on user choice
#include <stdio.h>
int main() {
int choice;
float num1, num2, result;
printf("\nEnter two numbers: ");
scanf("%f %f", &num1, &num2);

printf("Enter your choice (1: Sum, 2: Subtract, 3: Multiply, 4: Divide): ");


scanf("%d", &choice);

switch (choice) {
case 1:
result = num1 + num2;
printf("Sum: %f\n", result);
break;
case 2:
result = num1 - num2;
printf("Difference: %f\n", result);
break;
case 3:
result = num1 * num2;
printf("Product: %f\n", result);
break;
case 4:
if (num2 != 0) {
result = num1 / num2;
printf("Quotient: %f\n", result);
} else {
printf("Error: Division by zero\n");
}
break;
default:
printf("Wrong choice\n");
}

You might also like