Assignment
1. Number Sign Checker
• Write a program that reads an integer x from the user.
• If x is greater than 0, print "Positive".
• If x is equal to 0, print "Zero".
• Otherwise, print "Negative".
2. Even or Odd
• Write a program that reads an integer from the user.
• If the number is even, print "Even".
• Otherwise, print "Odd".
3. Pass or Fail
• Write a program that reads an integer score (0 to 100) from the user.
• If the score is 40 or above, print "Pass".
• Otherwise, print "Fail".
4. Voting Eligibility
• Write a program that reads an integer age from the user.
• If age is 18 or above, print "Eligible to vote".
• Otherwise, print "Not eligible to vote".
5. Maximum of Three Numbers
• Write a program that reads three integers from the user.
• Print the largest of the three integers.
Sample Solutions in C
You can copy each block as a standalone program, or combine them into a single program
with multiple functions. For brevity, each solution is shown as an independent main().
1. Number Sign Checker (C)
c
CopyEdit
#include <stdio.h>
int main() {
int x;
printf("Enter an integer: ");
scanf("%d", &x);
if (x > 0) {
printf("Positive\n");
} else if (x == 0) {
printf("Zero\n");
} else {
printf("Negative\n");
}
return 0;
}
2. Even or Odd (C)
c
CopyEdit
#include <stdio.h>
int main() {
int num;
printf("Enter an integer: ");
scanf("%d", &num);
if (num % 2 == 0) {
printf("Even\n");
} else {
printf("Odd\n");
}
return 0;
}
3. Pass or Fail (C)
c
CopyEdit
#include <stdio.h>
int main() {
int score;
printf("Enter your score (0-100): ");
scanf("%d", &score);
if (score >= 40) {
printf("Pass\n");
} else {
printf("Fail\n");
}
return 0;
}
4. Voting Eligibility (C)
c
CopyEdit
#include <stdio.h>
int main() {
int age;
printf("Enter your age: ");
scanf("%d", &age);
if (age >= 18) {
printf("Eligible to vote\n");
} else {
printf("Not eligible to vote\n");
}
return 0;
}
5. Maximum of Three Numbers (C)
c
CopyEdit
#include <stdio.h>
int main() {
int a, b, c;
printf("Enter three integers: ");
scanf("%d %d %d", &a, &b, &c);
if (a >= b && a >= c) {
printf("%d is the largest\n", a);
} else if (b >= a && b >= c) {
printf("%d is the largest\n", b);
} else {
printf("%d is the largest\n", c);
}
return 0;
}
Sample Solutions in Python
Each snippet can be run independently. Simply copy, paste, and run in a Python
environment (e.g., an online compiler or local IDE).
1. Number Sign Checker (Python)
python
CopyEdit
x = int(input("Enter an integer: "))
if x > 0:
print("Positive")
elif x == 0:
print("Zero")
else:
print("Negative")
2. Even or Odd (Python)
python
CopyEdit
num = int(input("Enter an integer: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
3. Pass or Fail (Python)
python
CopyEdit
score = int(input("Enter your score (0-100): "))
if score >= 40:
print("Pass")
else:
print("Fail")
4. Voting Eligibility (Python)
python
CopyEdit
age = int(input("Enter your age: "))
if age >= 18:
print("Eligible to vote")
else:
print("Not eligible to vote")
5. Maximum of Three Numbers (Python)
python
CopyEdit
a = int(input("Enter first integer: "))
b = int(input("Enter second integer: "))
c = int(input("Enter third integer: "))
if a >= b and a >= c:
print(a, "is the largest")
elif b >= a and b >= c:
print(b, "is the largest")
else:
print(c, "is the largest")
Tips & Best Practices
• Always validate user input (e.g., check if the input is within expected ranges).
• Use descriptive variable names to make your code more understandable.
• In C, always include #include <stdio.h> for I/O functions like printf and scanf.
• In Python, indentation matters—be consistent with spaces or tabs.