0% found this document useful (0 votes)
6 views4 pages

C Programs for Quadrants and Eligibility

The document contains multiple C programming tasks including determining the quadrant of a coordinate point, checking eligibility for admission based on marks, displaying messages based on temperature ranges, identifying triangle types, and implementing a number guessing game. Each task includes specific conditions and sample code to demonstrate the implementation. The programs utilize basic control structures such as if statements and loops.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

C Programs for Quadrants and Eligibility

The document contains multiple C programming tasks including determining the quadrant of a coordinate point, checking eligibility for admission based on marks, displaying messages based on temperature ranges, identifying triangle types, and implementing a number guessing game. Each task includes specific conditions and sample code to demonstrate the implementation. The programs utilize basic control structures such as if statements and loops.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1.

Write a C program to accept a coordinate point in an XY coordinate system


and determine in which quadrant the coordinate point lies.

Quadrant I: x > 0 and y > 0


Quadrant II: x < 0 and y > 0
Quadrant III: x < 0 and y < 0
Quadrant IV: x > 0 and y < 0
On the Y-axis: x == 0 and y != 0
On the X-axis: y == 0 and x != 0
2. Write a C program to determine eligibility for admission to a professional
course based on the following criteria:
Eligibility Criteria : Marks in Maths >=65 and Marks in Phy >=55 and Marks in
Chem>=50 and Total in all three subject >=190 or Total in Maths and Physics
>=140 ------------------------------------- Input the marks obtained in Physics :65
Input the marks obtained in Chemistry :51 Input the marks obtained in
Mathematics :72 Total marks of Maths, Physics and Chemistry : 188 Total
marks of Maths and Physics : 137 The candidate is not eligible.
#include <stdio.h>

int main() {
int maths, physics, chemistry, total, totalMathsPhysics;

// Input marks
printf("Enter marks in Maths: ");
scanf("%d", &maths);
printf("Enter marks in Physics: ");
scanf("%d", &physics);
printf("Enter marks in Chemistry: ");
scanf("%d", &chemistry);

// Calculate totals
total = maths + physics + chemistry;
totalMathsPhysics = maths + physics;

// Check conditions
if (maths >= 65) {
if (physics >= 55) {
if (chemistry >= 50) {
if (total >= 190) {
printf("Eligible\n");
} else {
if (totalMathsPhysics >= 140) {
printf("Eligible\n");
} else {
printf("Not Eligible\n");
}
}
} else {
printf("Not Eligible\n");
}
} else {
printf("Not Eligible\n");
}
} else {
printf("Not Eligible\n");
}

return 0;
}
[Link] a C program to read temperature in centigrade and display a suitable
message according to the temperature state below:
Temp < 0 then Freezing weather
Temp 0-10 then Very Cold weather
Temp 10-20 then Cold weather
Temp 20-30 then Normal in Temp
Temp 30-40 then Its Hot
Temp >=40 then Its Very Hot
[Link] a C program to check whether a triangle is Equilateral, Isosceles or Scalene.

Looping Statements
Write a C program that generates a random number between 1 and 20 and asks the
user to guess it. Use a while loop to give the user multiple chances until they guess
the correct number.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main() {
srand(time(NULL)); // Seed the random number generator with the current time
int targetNumber = rand() % 20 + 1; // Generate a random number between 1
and 20

int userGuess; // Variable to store the user's guess


int attempts = 0; // Variable to count the number of attempts

printf("Guess the number between 1 and 20:\n");

// Start a while loop to give the user multiple chances


while (1) {
printf("Input your guess: ");
scanf("%d", &userGuess); // Read the user's guess

attempts++; // Increment the number of attempts

// Check if the guess is correct


if (userGuess == targetNumber) {
printf("Congratulations! You guessed the correct number in %d attempts.\n",
attempts);
break; // Exit the loop if the guess is correct
} else {
printf("Incorrect guess. Try again!\n");
}
}

Common questions

Powered by AI

The guessing game program in C involves generating a random number between 1 and 20 using srand and rand functions seeded with the current time. It uses a while loop to repeatedly prompt the user to enter a guess. Each guess is checked against the target number, and the number of attempts is counted. If the guess is correct, the program congratulates the user and exits the loop. If the guess is incorrect, the program prompts the user to try again until the correct number is guessed .

Using a while loop in a number guessing game allows for repeated interactions where the user can continuously make guesses until they guess correctly. This looping construct keeps the program active and responsive, improving user engagement by providing multiple chances to succeed. It also helps manage program flow control efficiently, as it can easily exit the loop once the correct guess is made .

To determine eligibility for admission into a professional course using a C program, a candidate must meet the following criteria: Marks in Maths must be >= 65, Marks in Physics >= 55, Marks in Chemistry >= 50, and the total marks across all three subjects must be >= 190. Alternatively, if the total marks in only Maths and Physics are >= 140, the candidate is also eligible, even if the total for all three subjects is less than 190 .

In a C program, you can determine in which quadrant a given coordinate point (x, y) lies based on the values of x and y. The conditions are as follows: if x > 0 and y > 0, the point lies in Quadrant I; if x < 0 and y > 0, it lies in Quadrant II; if x < 0 and y < 0, it lies in Quadrant III; if x > 0 and y < 0, it lies in Quadrant IV. Points on the Y-axis have x = 0 and y != 0, while points on the X-axis have y = 0 and x != 0 .

In the decision-making process, the C program checks if the x-coordinate is 0 and the y-coordinate is not 0 to determine if the point lies on the Y-axis. Conversely, if the y-coordinate is 0 and the x-coordinate is not 0, the point lies on the X-axis. This process uses simple conditional checks to categorize the point accurately .

Seeding the random number generator using srand with the current time ensures that the random number sequence differs each time the program is run. This makes the guessing game unpredictable, enhancing its replay value and fairness, as the sequence of random numbers generated will not be the same for subsequent runs unless the seed is repeated .

A triangle can be classified in a C program using these conditions: it is equilateral if all three sides are equal, isosceles if any two sides are equal, and scalene if all three sides are different .

In a C program, the weather state can be determined by checking the temperature value against predefined ranges: if the temperature is less than 0, it is 'Freezing weather'; if it is between 0 and 10, it is 'Very Cold weather'; between 10 and 20 is 'Cold weather'; between 20 and 30 is 'Normal in Temp'; between 30 and 40 is 'Hot'; and 40 or above is 'Very Hot' .

The logic used in the C program categorizes weather conditions into fixed ranges of temperatures, which is straightforward for clearly differentiated states in a limited scale. However, this approach might need adaptation for different temperature scales (e.g., Fahrenheit) or more granular scenarios (e.g., regional climate variations), where more ranges or specific modifiers (like humidity or wind chill) might be necessary for more accurate classifications .

A candidate could be deemed ineligible if, despite having a high total score, they fail to meet the individual subject thresholds required for eligibility. For example, even if the total score is close to or exceeds 190, if the individual marks in Maths are below 65, Physics below 55, or Chemistry below 50, the candidate will be ineligible because each individual condition must be satisfied to meet the criteria .

You might also like