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

Assignment 3

The document outlines five programming tasks in C, including comparing two numbers, finding the smallest among three numbers, checking if a number is even or odd, determining if a number is positive, negative, or zero, and checking if a year is a leap year. Each task includes the aim, code, output example, and conclusion confirming the program's correctness. The tasks demonstrate fundamental programming concepts and conditional statements.

Uploaded by

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

Assignment 3

The document outlines five programming tasks in C, including comparing two numbers, finding the smallest among three numbers, checking if a number is even or odd, determining if a number is positive, negative, or zero, and checking if a year is a leap year. Each task includes the aim, code, output example, and conclusion confirming the program's correctness. The tasks demonstrate fundamental programming concepts and conditional statements.

Uploaded by

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

Q1) Compare Two Numbers

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:

To find the smallest number among three given numbers.

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);

if (a < b && a < c) {


printf("%d is the Smallest Number", a);
} else if (b < a && b < c) {
printf("%d is the Smallest Number", b);
} else if (c < a && c < b) {
printf("%d is the Smallest Number", c);
} else {
printf("All numbers are equal");
}

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:

To determine if a given number is even or odd.

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:

To check whether a given number is positive, negative, or zero.

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:

To check whether a given year is a leap year or not.

2. Code:
c
CopyEdit
#include <stdio.h>
int main() {
int year;
printf("Enter a Year: ");
scanf("%d", &year);

if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {


printf("%d is a Leap Year", year);
} else {
printf("%d is not a Leap Year", 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.

You might also like