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

Control Loop

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)
7 views4 pages

Control Loop

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

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;
}
3.Write 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
4.Write 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");
}
}

You might also like