#include<stdio.h>
int main(){
int a = 0; // Output => Zero
//int a = 1; // No Output
if( a == 0 ){ // Testing Equlity Operator [==]
printf("Zero\n");
}
return 0;
}
#include<stdio.h>
int main(){
int a = 0; // Output => Zero
//int a = 1; // Output => Not Zero
if( a == 0 ){ // Testing Equlity Operator [==]
printf("Zero\n");
}
if( a != 0 ){ // Testing Not Equlity Operator [!=]
printf("Not Zero\n");
}
return 0;
}
#include<stdio.h>
int main(){
int a = 0; // Output => Zero
//int a = 1; // Output => Not Zero
if( a == 0 ){
printf("Zero\n");
}
else{ // Else block will execute when (a == 0) is false
printf("Not Zero\n");
}
return 0;
}
#include<stdio.h>
int main(){
int a = 0; // Output => Zero
//int a = 1; // Output => Not Zero
if( a ){ // if evaluate 0 as FALSE and non-zero value as TRUE
// This block will execute when the value of a is non-zero
printf("Not Zero\n");
}
else{
// This block will execute when the value of a is 0
printf("Zero\n");
}
return 0;
}
#include<stdio.h>
int main(){
int a = 0; // Output => Zero
//int a = 1; // Output => Not Zero
// Logical NOT Operator
if( !a ){ // when a=0, it means a is FALSE, !a means TRUE
// This block will execute when the value of a is 0
printf("Zero\n");
}
else{
// This block will execute when the value of a is non-zero
printf("Not Zero\n");
}
return 0;
}
#include<stdio.h>
int main(){
int a = 5; // Output => Positive
//int a = -5; // Output => Negative
//int a = 0; // No Output
if( a > 0 ){ // Testing Grater Then Operator [>]
printf("Positive\n");
}
if( a < 0 ){ // Testing Less Then Operator [<]
printf("Negative\n");
}
return 0;
}
#include<stdio.h>
int main(){
int a = 5; // Output => Positive
//int a = -5; // Output => Negative
//int a = 0; // Output => Negative
if( a > 0 ){ // Testing Grater Then Operator [>]
printf("Positive\n");
}
else{ // Else block will execute when (a > 0) is false
printf("Negative\n");
}
return 0;
}
#include<stdio.h>
int main(){
int a = 5; // Output => Positive
//int a = -5; // Output => Negative
//int a = 0; // Output => Positive
if( a >= 0 ){ // Testing Grater Then or Equal Operator [>=]
printf("Positive\n");
// Zero is neither Position nor Negative
// So This Solution is not perfect
}
else{ // Else block will execute when (a > 0) is false
printf("Negative\n");
}
return 0;
}
#include<stdio.h>
int main(){
int num = 5; // Output => Positive
//int num = -5; // Output => Negative
//int num = 0; // Output => Zero
if( num > 0 ){ // Testing Grater Then Operator [>]
printf("Positive\n");
}
if( num < 0 ){ // Testing Less Then Operator [<]
printf("Negative\n");
}
if( num == 0 ){ // Testing Equlity Operator [==]
printf("Zero\n");
}
return 0;
}
#include<stdio.h>
int main(){
int num = 5; // Output => Positive
//int num = -5; // Output => Negative
//int num = 0; // Output => Zero
if( num > 0 ){ // Testing Grater Then Operator [>]
printf("Positive\n");
}
else if( num < 0 ){ // Testing Less Then Operator [<]
printf("Negative\n");
}
else if( num == 0 ){ // Testing Equlity Operator [==]
printf("Zero\n");
}
return 0;
}
#include<stdio.h>
int main(){
int num = 5; // Output => Positive
//int num = -5; // Output => Negative
//int num = 0; // Output => Zero
if( num > 0 ){ // Testing Grater Then Operator [>]
printf("Positive\n");
}
else if( num < 0 ){ // Testing Less Then Operator [<]
printf("Negative\n");
}
else{
// This else block will execute when both previous conditions are false
printf("Zero\n");
}
return 0;
}
#include<stdio.h>
int main(){
int num = 5; // Output => Positive
//int num = -5; // Output => Negative
//int num = 0; // Output => Zero
if( num == 0 ){ // Testing Equlity Operator [==]
printf("Zero\n");
}
else{
if( num > 0 ){ // Testing Grater Then Operator [>]
printf("Positive\n");
}
//else if( num < 0 ){ // Testing Less Then Operator [<]
else{
printf("Negative\n");
}
}
return 0;
}
#include<stdio.h>
int main(){
int age = 20; // Output => Voter
//int age = 15; // Output => Not Voter
//int age = 18; // No Output
if(age > 18){
printf("Eligible to Vote\n");
}
if(age < 18){
printf("Not Eligible to Vote\n");
}
return 0;
}
#include<stdio.h>
int main(){
int age = 20; // Output => Voter
//int age = 15; // Output => Not Voter
//int age = 18; // Output => Voter
if(age == 18){
printf("Eligible to Vote\n");
}
if(age > 18){
printf("Eligible to Vote\n");
}
if(age < 18){
printf("Not Eligible to Vote\n");
}
return 0;
}
#include<stdio.h>
int main(){
int age = 20; // Output => Voter
//int age = 15; // Output => Not Voter
//int age = 18; // Output => Voter
if(age == 18 || age > 18){
printf("Eligible to Vote\n");
}
if(age < 18){
printf("Not Eligible to Vote\n");
}
return 0;
}
#include<stdio.h>
int main(){
int age = 20; // Output => Voter
//int age = 15; // Output => Not Voter
//int age = 18; // Output => Voter
if(age >= 18){
printf("Eligible to Vote\n");
}
if(age < 18){
printf("Not Eligible to Vote\n");
}
return 0;
}
Test Voting Eligibility 2 (if else solution)
#include<stdio.h>
int main(){
int age = 20; // Output => Voter
//int age = 15; // Output => Not Voter
//int age = 18; // Output => Voter
if(age >= 18){
printf("Eligible to Vote\n");
}
else if(age < 18){
printf("Not Eligible to Vote\n");
}
return 0;
}
#include<stdio.h>
int main(){
int age = 20; // Output => Voter
//int age = 15; // Output => Not Voter
//int age = 18; // Output => Voter
if(age >= 18){
printf("Eligible to Vote\n");
}
else{
printf("Not Eligible to Vote\n");
}
return 0;
}
#include<stdio.h>
#define VOTE_AGE 18 // Define VOTE_AGE macro
int main(){
int age = 20; // Output => Voter
//int age = 15; // Output => Not Voter
//int age = 18; // Output => Voter
if( age >= VOTE_AGE ){
printf("Eligible to Vote\n");
}
else{
printf("Not Eligible to Vote\n");
}
return 0;
}
Test Voting Eligibility 3 (alternative solution)
#include<stdio.h>
int main(){
int age = 20; // Output => Voter
//int age = 15; // Output => Not Voter
//int age = 18; // Output => Voter
if(age < 18){
printf("Not Eligible to Vote\n");
}
else{
printf("Eligible to Vote\n");
}
return 0;
}
#include<stdio.h>
int main(){
int age = 20; // Output => Voter
//int age = 15; // Output => Not Voter
//int age = 18; // Output => Voter
if(age <= 17){
printf("Not Eligible to Vote\n");
}
else{
printf("Eligible to Vote\n");
}
return 0;
}
#include<stdio.h>
int main(){
int age = 20; // Output => Eligible to apply
//int age = 15; // Output => Not Eligible to apply
//int age = 38; // Output => Not Eligible to apply
if(age >= 18){ // Testing Grater Then or Equal Operator [>=]
if( age <= 35 ){ // Testing Less Then or Equal Operator [<=]
printf("Eligible to apply\n");
}
else{
printf("Not eligible to apply\n");
}
}
else{
printf("Not eligible to apply\n");
}
return 0;
}
#include<stdio.h>
int main(){
int age = 20; // Output => Eligible to apply
//int age = 15; // Output => Not Eligible to apply
//int age = 38; // Output => Not Eligible to apply
if(age >= 18 && age <= 35){ // Testing Logical AND Operator [&&]
// Print "Eligible to apply" if the age is between 18 and 35 inclusive
printf("Eligible to apply\n");
}
else{
// Print "Not Eligible to apply" if the age is outside the range
printf("Not eligible to apply\n");
}
return 0;
}
#include<stdio.h>
int main(){
int age = 20; // Output => Eligible to apply
//int age = 15; // Output => Not Eligible to apply
//int age = 38; // Output => Not Eligible to apply
if(age <= 18){ // Testing Less Then or Equal Operator [<=]
printf("Not eligible to apply\n");
}
else if( age >= 35 ){ // Testing Grater Then or Equal Operator [>=]
printf("Not eligible to apply\n");
}
else{
printf("Eligible to apply\n");
}
return 0;
}
#include<stdio.h>
int main(){
int age = 20; // Output => Eligible to apply
//int age = 15; // Output => Not Eligible to apply
//int age = 38; // Output => Not Eligible to apply
if(age <= 18 || age >= 35){ // Testing Logical OR Operator [||]
printf("Not eligible to apply\n");
}
else{
printf("Eligible to apply\n");
}
return 0;
}