0% found this document useful (0 votes)
217 views

Cse115-Lab-Manual-4-If - Else Part1

This document provides examples of C programs that use if-else conditional statements to check various logical conditions and return appropriate outputs. It includes programs to find the maximum and minimum of two numbers, the maximum of three numbers, check if a year is a leap year, and exercises for the reader to write similar programs for other conditional checks like valid months, employee eligibility, number properties, triangle properties, hexadecimal digits, and geometric shapes.

Uploaded by

Abid
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
217 views

Cse115-Lab-Manual-4-If - Else Part1

This document provides examples of C programs that use if-else conditional statements to check various logical conditions and return appropriate outputs. It includes programs to find the maximum and minimum of two numbers, the maximum of three numbers, check if a year is a leap year, and exercises for the reader to write similar programs for other conditional checks like valid months, employee eligibility, number properties, triangle properties, hexadecimal digits, and geometric shapes.

Uploaded by

Abid
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

CSE 115 Lab on if-else (ARa2)

1. C program to find maximum between two numbers:

void main()
{
int n1, n2;

printf("Enter any two numbers:\n");


scanf("%d %d", &n1, &n2);

// Check if n1 > n2 or not and prints the maximum


if(n1 > n2)
{
printf("%d is maximum", n1);
}
else
{
printf("%d is maximum", n2);
}
}

Try it yourself 1a: Write a C program to find minimum between two numbers.

2. C program to find maximum among three numbers:

void main()
{
int x,y,z;

/*
* Reads any two integer values from user
*/
printf("Enter three distinct numbers:\n");
scanf("%d %d %d", &x, &y, &z);

if(x>y && x>z) //Check if x is the maximum


printf("%d is maximum", x);
else if (y>z)//if x is not max then y or z is max; Check which.
printf("%d is maximum", y);
else
printf("%d is maximum", z);
}

Try it yourself 2: Write a C program to find minimum among three numbers.


3. C program to check Leap Year (a year is a leap year if – (i) it is divisible by 4 but not divisible by 100 OR (ii)
it is divisible by 400):

#include <stdio.h>

void main()
{
int year;

/* Read year from user */


printf("Enter year : ");
scanf("%d", &year);

/* Check for leap year */


if(((year%4 == 0) && (year%100 !=0)) || (year%400==0))
{
printf("LEAP YEAR");
}
else
{
printf("Not Leap Year");
}
}

EXERCISES:

1. Write a C program to enter month number and print number of days in month
2. Write a C program that decides whether a person is eligible to work in a particular company or not. The
company policy is: If the person’s age is between 25 and 45, s/he are eligible to work. Otherwise, your
software should say “You are too young or too old”.
3. Write a C program to check if an input integer is a multiple of either 2 or 5 but not a multiple of both.
E.g. of valid numbers are 4, 6, 8, 12, 14, 15, 16, 25, etc. E.g. of invalid numbers are 1, 3, 7, 9, 10, 20, etc.
4. Write a C program to check whether an input number is a multiple of only 5 (e.g. 5, 10, 15, ...), only 11
(e.g. 11, 22, 33, ...), both 5 and 11 (e.g. 55, 110, ....), or neither of them (e.g. 2,3, 4, 6, 7, 8, 9, 12, ....).
5. Check if the roots of the equation: ax2+bx+c=0 are real or not. If they are real, then print them;
otherwise print “No real root exist.” Read a,b,c from user.

ASSIGNMENT:

1. Write a C program to input sides of a triangle and check whether triangle is valid or not (Hint: if sum of
any two sides of a triangle is greater than the third side then the triangle is valid)
2. Write a C program to input all angles of a triangle and check whether triangle is valid or not. (Hint: sum
of all angles of any triangle is 180 degrees)
3. Read a character from user and check if it is a valid hexadecimal digit or not. Hint: a char is a valid
hexadecimal digit if it is one of these characters: ‘0’, ‘1’, ... , ‘9’, ‘a’, ’b’, ... , ’f’, ‘A’,’B’, ... ,’F’
4. Read a floating point number from user and check if it has any fractional part (e.g. 4.5, 6.9,...) or not
(e.g. 4, 5, ...). If it has a fractional part then print “Not an integer”, otherwise print “integer”.
5. Write a C program that reads the radius r of a circle and the side a of a square from user and then
checks if that square can be placed inside that circle or not. Hint: Use Pythagorean theorem.

You might also like