Primary U.S. interstate highways are numbered 1-99. Odd numbers (like the 5 or 95) go north/south, and events (like the 10 or 90) go east/west. Auxiliary highways are numbered 100-999, and service the primary highway indicated by the rightmost two digits. Thus, I-405 services I-5, and I-290 services I-90. Given a highway number, indicate whether it is a primary or auxiliary highway. If auxiliary, indicate what primary highway it serves. Also indicate if the (primary) highway runs north/south or east/west.

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;

}

MrRoyal

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

Other Questions