CSC 303: DIGITAL LOGIC AND COMPUTER DESIGN CSC 219 (Programming in C) Lab Exercise 2 This lab provides more C input and output practice. Write a program called lab2.c. Your lab2.c program should...

1 answer below »
All instructions in the Lab_Exercises_2 file


CSC 303: DIGITAL LOGIC AND COMPUTER DESIGN CSC 219 (Programming in C) Lab Exercise 2 This lab provides more C input and output practice. Write a program called lab2.c. Your lab2.c program should “convert” an integer into another base. But note that the conversion is only to OUTPUT the read in integer in a different base, not hold it internally. The input integer could be in decimal, octal or hexadecimal. The output could be converted into any of the bases. A sample run is below. The user’s response is in boldface. Base of input integer: Enter d for decimal, h for hexadecimal or o for octal: d Enter the number: 178 Enter the base of the output (d, h or o): h The integer 178 in decimal is b2 in hexadecimal Do you wish to do another? (Y or N): Y Base of input integer: Enter d for decimal, h for hexadecimal or o for octal: o Enter the number: 423 Enter the base of the output: d The integer 423 in octal is 275 in decimal Do you wish to do another? (Y or N): N Print your .c file and the sample output and submit HINT: This program is simpler than some of you may think it to be. Recall how the embedded conversion strings are used in C printf() and scanf() calls as discussed in class.
Answered Same DayOct 07, 2021

Answer To: CSC 303: DIGITAL LOGIC AND COMPUTER DESIGN CSC 219 (Programming in C) Lab Exercise 2 This lab...

Darshan answered on Oct 08 2021
129 Votes
1. Lab2.c file
#include
int main()
{
    char input;
    char output;
    char user;
    int dat
a;
do{
    printf("Base of input integer: Enter d for decimal, h for hexadecimal or o for octal:");
    scanf(" %c",&input);    
    printf("Enter the number: ");
    switch(input)
    {
            case 'd':
                    scanf("%d",&data);
            break;
            case 'h':
                    scanf("%x",&data);
            break;    
            case 'o':
                    scanf("%o",&data);
            break;
            default:
            printf("Wrong input\n");
            break;
    }
    
    printf("Enter the base of the...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here