Answer :
Answer:
The C code for the problem is given below
Explanation:
#include <stdio.h>
int main() {
int highwayNumber;
int primaryNumber;
scanf("%d", &highwayNumber);
if (highwayNumber >= 1 && highwayNumber <= 999) {
if (highwayNumber <= 99) {
if (highwayNumber % 2 == 0) {
printf("I-%d is primary, going east/west.\n", highwayNumber);
} else {
printf("I-%d is primary, going north/south.\n", highwayNumber);
}
} else {
primaryNumber = highwayNumber;
highwayNumber %= 100;
if (highwayNumber % 2 == 0) {
printf("I-%d is auxiliary, serving the I-%d, going east/west.\n", primaryNumber, highwayNumber);
} else {
printf("I-%d is auxiliary, serving the I-%d, going north/south.\n", primaryNumber, highwayNumber);
}
}
} else {
printf("%d is not a valid interstate highway number.\n", highwayNumber);
}
return 0;
}
The interstate highway program illustrates the use of conditional statements.
In programming, conditional statements are dependent on their truth value for their execution.
The program in Java where comments are used to explain each line is as follows:
import java.util.*;
public class interstateHighway {
public static void main(String [] args){
Scanner scnr = new Scanner(System.in);
//This declares the necessary variables as integer
int highwayNumber, primaryNumber;
//This gets input for the highwayNumber
highwayNumber = scnr.nextInt();
//This checks if the highwayNumber is out of range of 1 and 999
if (highwayNumber <1 || highwayNumber > 999){
//If the condition is true, then highwayNumber is not valid
System.out.print(highwayNumber+" is invalid ");
}
//If highwayNumber is valid
else{
//This checks if highwayNumber is less than 100
if (highwayNumber< 100){
if (highwayNumber%2 == 0){
//Even highwayNumber are primary and going east/west
System.out.print("I-"+highwayNumber+" is primary, going east/west.");
}
else{
//Odd highwayNumber are primary and going north/south
System.out.print("I-"+highwayNumber+" is primary, going north/south.");
}
}
//If highwayNumber is 100 or more
else{
if ((highwayNumber%100) % 2 == 0){
//Even highwayNumber are auxiliary and going east/west
System.out.print("I-"+highwayNumber+" is auxiliary, going east/west.");
} else{
//Even highwayNumber are auxiliary and going north/south
System.out.print("I-"+highwayNumber+" is auxiliary, going north/south.");
} } } } }
Read more about conditional statements at:
https://brainly.com/question/14551419