Assignment 3
Assignment 3
1. Aim:
To compare two numbers and determine if they are equal or which one is greater.
2. Code:
c
CopyEdit
#include <stdio.h>
int main() {
int a, b;
printf("Enter the number of a:\n ");
scanf("%d", &a);
printf("Enter the number of b:\n ");
scanf("%d", &b);
if (a == b) {
printf("Both are Equal");
} else if (a > b) {
printf("%d is greater than %d", a, b);
} else {
printf("%d is greater than %d", b, a);
}
return 0;
}
3. Output:
less
CopyEdit
Enter the number of a: 45
Enter the number of b: 76
76 is greater than 45
4. Conclusion:
The program successfully compares two numbers and determines which one is greater or if
they are equal.
Q2) Find the Smallest Number Among Three
1. Aim:
2. Code:
c
CopyEdit
#include <stdio.h>
int main() {
int a, b, c;
printf("Enter the number of a:\n ");
scanf("%d", &a);
printf("Enter the number of b:\n ");
scanf("%d", &b);
printf("Enter the number of c:\n ");
scanf("%d", &c);
return 0;
}
3. Output:
typescript
CopyEdit
Enter the number of a: 234
Enter the number of b: 56
Enter the number of c: 65
56 is the Smallest Number
4. Conclusion:
The program correctly finds and prints the smallest number among three given inputs.
Q3) Check Whether a Number is Even or Odd
1. Aim:
2. Code:
c
CopyEdit
#include <stdio.h>
int main() {
int n;
printf("Enter a number: ");
scanf("%d", &n);
if (n % 2 == 0) {
printf("%d is an Even Number", n);
} else {
printf("%d is an Odd Number", n);
}
return 0;
}
3. Output:
mathematica
CopyEdit
Enter a number: 12
12 is an Even Number
4. Conclusion:
The program correctly determines whether the given number is even or odd.
Q4) Check Whether a Number is Positive, Negative, or
Zero
1. Aim:
2. Code:
c
CopyEdit
#include <stdio.h>
int main() {
double n;
printf("Enter a Number: ");
scanf("%lf", &n);
if (n == 0) {
printf("You entered 0");
} else if (n > 0) {
printf("%.2lf is positive", n);
} else {
printf("%.2lf is negative", n);
}
return 0;
}
3. Output:
mathematica
CopyEdit
Enter a Number: 546
546.00 is positive
4. Conclusion:
The program correctly determines whether the given number is positive, negative, or zero.
Q5) Check if a Year is a Leap Year
1. Aim:
2. Code:
c
CopyEdit
#include <stdio.h>
int main() {
int year;
printf("Enter a Year: ");
scanf("%d", &year);
return 0;
}
3. Output:
yaml
CopyEdit
Enter a Year: 2024
2024 is a Leap Year
4. Conclusion:
The program correctly determines whether the given year is a leap year or not using the leap
year conditions.