coding assignment Question and solution (if else)
coding assignment Question and solution (if else)
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().
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;
}
int main() {
int num;
printf("Enter an integer: ");
scanf("%d", &num);
if (num % 2 == 0) {
printf("Even\n");
} else {
printf("Odd\n");
}
return 0;
}
int main() {
int score;
printf("Enter your score (0-100): ");
scanf("%d", &score);
return 0;
}
int main() {
int age;
printf("Enter your age: ");
scanf("%d", &age);
return 0;
}
int main() {
int a, b, c;
printf("Enter three integers: ");
scanf("%d %d %d", &a, &b, &c);
return 0;
}
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")