Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

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 »
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 Day Oct 07, 2021

Solution

Darshan answered on Oct 08 2021
140 Votes
1. Lab2.c file
#includeint main()
{
    char input;
    char output;
    char user;
    int data;
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);
            
eak;
            case 'h':
                    scanf("%x",&data);
            
eak;    
            case 'o':
                    scanf("%o",&data);
            
eak;
            default:
            printf("Wrong input\n");
            
eak;
    }
    
    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