Thanks to visit codestin.com
Credit goes to www.scribd.com

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

Introduction To Computer Programming Quiz-1 Answer

The document contains two C programming tasks: the first task involves creating a program to input vote counts for four political parties and display results based on user input, while the second task requires writing a program to calculate Body Mass Index (BMI) and classify it into categories such as underweight, normal weight, overweight, and obesity. Both tasks include detailed instructions and sample code implementations. The document serves as a laboratory quiz for an introduction to computer programming course.

Uploaded by

adagozek
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)
4 views2 pages

Introduction To Computer Programming Quiz-1 Answer

The document contains two C programming tasks: the first task involves creating a program to input vote counts for four political parties and display results based on user input, while the second task requires writing a program to calculate Body Mass Index (BMI) and classify it into categories such as underweight, normal weight, overweight, and obesity. Both tasks include detailed instructions and sample code implementations. The document serves as a laboratory quiz for an introduction to computer programming course.

Uploaded by

adagozek
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/ 2

07.03.

2024
Introduction to Computer Programming
Laboratory QUİZ-1

1. Create a C program that prompts the user to input the vote counts
for four different political parties from an election. After the
votes are entered, the program should display a message asking
which party’s results the user wants to see on the screen. The user
should be instructed to enter the specific name on the party for
individual results or the character ‘X’ to display the results for
all parties. (You should also print the vote rates received by each
party as a percentage expression)

#include <stdio.h>

int main() {
int votesA, votesB, votesC, votesD, totalVotes;
char party;

// Prompt the user to enter the vote counts for each party
printf("Enter the vote count for Party A: ");
scanf("%d", &votesA);
printf("Enter the vote count for Party B: ");
scanf("%d", &votesB);
printf("Enter the vote count for Party C: ");
scanf("%d", &votesC);
printf("Enter the vote count for Party D: ");
scanf("%d", &votesD);

// Calculate the total votes


totalVotes = votesA + votesB + votesC + votesD;

// Ask the user which party's results they want to see


printf("Enter 'A', 'B', 'C', or 'D' to see individual results
or 'X' for all parties: ");
scanf(" %c", &party);

// Display the results based on the user's choice


if (party == 'X') {
printf("Party A: %d votes (%.2f%%)\n", votesA, (votesA /
(float)totalVotes) * 100);
printf("Party B: %d votes (%.2f%%)\n", votesB, (votesB /
(float)totalVotes) * 100);
printf("Party C: %d votes (%.2f%%)\n", votesC, (votesC /
(float)totalVotes) * 100);
printf("Party D: %d votes (%.2f%%)\n", votesD, (votesD /
(float)totalVotes) * 100);
} else if (party == 'A') {
printf("Party A: %d votes (%.2f%%)\n", votesA, (votesA /
(float)totalVotes) * 100);
} else if (party == 'B') {
printf("Party B: %d votes (%.2f%%)\n", votesB, (votesB /
(float)totalVotes) * 100);
} else if (party == 'C') {
printf("Party C: %d votes (%.2f%%)\n", votesC, (votesC /
(float)totalVotes) * 100);
} else if (party == 'D') {
printf("Party D: %d votes (%.2f%%)\n", votesD, (votesD /
(float)totalVotes) * 100);
} else {
printf("Invalid input. Please enter 'A', 'B', 'C', 'D', or
'X'.\n");
}
return 0;
}

2. Write a C program to calculate body mass index and display the


grade from the following grades:

Underweight - BMI < 18.5


Normal weight - 18.5 <= 25.0
Overweight - 25.0 <= 30.0
Obesity - 30.0 <= BMI

Where weight is taken in kilograms and height in meters.


Body Mass Index (or BMI) is calculated as your weight (in
kilograms) divided by the square of your height (in metres) or BMI
= Kg/M2.

#include <stdio.h>

int main(void) {
int weight; // Variable to store weight
float height, bmi; // Variables to store height and BMI

// Prompt user for weight and height


printf("Input the weight (in kilograms): ");
scanf("%d", &weight);
printf("Input the height (in meters): ");
scanf("%f", &height);

// Calculate BMI using the provided formula


bmi = weight / (height * height);

// Display the calculated BMI


printf("BMI = %f\n", bmi);

// Determine BMI grade and display it using if-else


statements
printf("\nGrade: ");
if (bmi < 18.5) {
printf("Underweight\n");
} else if (bmi >= 18.5 && bmi < 25) {
printf("Normal\n");
} else if (bmi >= 25 && bmi < 30) {
printf("Overweight\n");
} else if (bmi >= 30) {
printf("Obese\n");
} else {
printf("Error\n");
}

return 0;
}

You might also like