Answer to Question #260362 in C for Mr Z

Question #260362

5. Using the online compiler (or Dev C++):

• Enter the code

int main(int argc, char *argv[]) {
	
	int a;
	
	// Obtain the value of integer a
	printf("Enter the value of integer a: ");
	scanf("%d", &a);
	printf("\n\n");
	
	// Determine using a switch construct whether
	// a is an odd digit, even digit or multiple digits
	switch(a)
	{
	case 0:
	case 2:
	case 4:
	case 6:
	case 8:
		printf("a (%d) is an even digit\n", a);
		break;

	case 1:
	case 3:
	case 5:
	case 7:
	case 9:
		printf("a (%d) is an odd digit\n", a);
		break;
		
	default:
		printf("a (%d) contains multiple digits\n", a);
	}
	
	system("pause");
	return 0;


• Enter an ODD single digit value that is less than 10.

• Enter an EVEN single digit value that is less than 10.

• Enter a value that is greater than 10.

• Write a code on its functionality comparing the outputs against the source code.

• Modify the program In other words for a 0, the program would display “ZERO” for a 7 the program, would display “SEVEN”









1
Expert's answer
2021-11-02T17:35:25-0400

The program prints the input value in the brackets, and then "Is an even digit" if it is an even digit (that is 0, 2, 4, 6, or 8), "is an odd digit" if it is an odd digit (that is 1, 3, 5, 7 or 9) or "contains multiple digits" of the input value is less than 0 or greater than 9. Afterwards, the program waits for the user to press any kye and terminates.


#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
    
    int a;
    
    // Obtain the value of integer a
    printf("Enter the value of integer a: ");
    scanf("%d", &a);
    printf("\n\n");
    
    // If a is a single digit print its value as a word
    switch(a)
    {
    case 0:
        printf("ZERO\n");
        break;
    case 2:
        printf("TWO\n");
        break;
    case 4:
        printf("FOUR\n");
        break;
    case 6:
        printf("SIX\n");
        break;
    case 8:
        printf("EIGHT\n");
        break;

    case 1:
        printf("ONE\n");
        break;
    case 3:
        printf("THREE\n");
        break;
    case 5:
        printf("FIVE\n");
        break;
    case 7:
        printf("SEVEN\n");
        break;
    case 9:
        printf("NINE\n");
        break;
        
    default:
        printf("a (%d) contains multiple digits\n", a);
    }
    
    system("pause");
    return 0;

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS