Using dowhile loops and switch statements Write a program to

Using do-while loop(s) and switch statements; Write a program to continuously read integers from the user in the range 0-15, and print their Hexadecimal representation based on the following table, your program should only stop execution if the user enter an invalid number (outside the accepted range).

Solution

// C code to determine hexadecimal from decimal

#include <stdio.h>

int main()
{
int inputdecimal;
char result;

do
{
printf(\"Enter decimal number(0-15): \");
scanf(\"%d\",&inputdecimal);

int temp = inputdecimal;

temp = temp % 16;

if( temp < 10)
temp =temp + 48;
else
temp = temp + 55;

result = temp;

printf(\"Hexadecimal value: %c\ \ \",result);

}while( inputdecimal >= 0 && inputdecimal <= 15 );

return 0;
}


/*

output:

Enter decimal number(0-15): 11
Hexadecimal value: B

Enter decimal number(0-15): 12
Hexadecimal value: C

*/

 Using do-while loop(s) and switch statements; Write a program to continuously read integers from the user in the range 0-15, and print their Hexadecimal repres

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site