Question

In: Computer Science

Write a code fragment in C language that tests the value of an integer num1. If...

Write a code fragment in C language that tests the value of an integer num1. If the value is 10, square num1. If it is 9, read a new value into num1. If it is 2 or 3, multiply num1 by 99 and print out the result. Implement your code using SWITCH statements

Solutions

Expert Solution

Here are the desired outputs

Output 1

Output 2

Output 3

Output 4

And here is the C code

#include <stdio.h>

int main(void) {
        int num1;
        
        L1:
        printf("Enter num1 value\n");
        scanf("%d",&num1);
        
        switch(num1)
        {
           case 10: num1=num1*num1;
                    printf("The new value of num is %d", num1);
                    break;
                    
           case 9: printf("Re-enter a new value for num1\n");
                    goto L1;
                    break;

      case 2: num1 = num1*99;
                 printf("The new value of num is %d", num1);
                    break;
                    
           case 3: num1 = num1*99;
                 printf("The new value of num is %d", num1);
                    break;
                    
           default: printf("Entered value of num1 isn't right. Either enter 9 or 10 or 2 or 3\n");
                     break;

        }
        return 0;
}

A humble request. If you liked the answer please don't forget to like or upvote it. Your appreciation motivates experts to help other students too. Thank you :)


Related Solutions

Write an interactive program that inputs a decimal num1 and an integer num2. If num1 is...
Write an interactive program that inputs a decimal num1 and an integer num2. If num1 is less than num2, then it displays "num 1 is less than num 2"; if they are identical, it starts over again; if . If num2 is less than num1, then it displays "num 2 is less than num 1
Write Java code that accepts the integer input (from keyboard) in an arraylist named num1 and...
Write Java code that accepts the integer input (from keyboard) in an arraylist named num1 and stores the even integers of num1 in another arraylist named evennum.
3) Consider the following IA32 assembly language code fragment. Assume that a, b and c are...
3) Consider the following IA32 assembly language code fragment. Assume that a, b and c are integer variables declared in the data segment. movl a, %eax movl b, %ebx cmpl %ebx, %eax jge L1 movl %eax, %ecx jmp L2 L1: movl %ebx, %ecx L2: movl %ecx, c Write the C code which is equivalent to the above assembly language code. You don't need to include the variable declarations, a function or anything like that, just show the 1 to 4...
Write a MIPS assembly language to transpose a square integer matrix in code
Write a MIPS assembly language to transpose a square integer matrix in code
/*Design and code a class Calculator that has the following * tow integer member variables, num1...
/*Design and code a class Calculator that has the following * tow integer member variables, num1 and num2. * - a method to display the sum of the two integers * - a method to display the product * - a method to display the difference * - a method to display the quotient * - a method to display the modulo (num1%num2) * - a method toString() to return num1 and num2 in a string * - Test your...
Javascript. Consider the following code fragment, that is supposed to compute the pixel value let c...
Javascript. Consider the following code fragment, that is supposed to compute the pixel value let c = image.getPixel(x, y); const m1 = (c[0] + c[1] + c[2]) / 3; c = image.getPixel(x + 1, y); const m2 = (c[0] + c[1] + c[2]) / 3; image.setPixel(x, y, [m1 - m2, m1 - m2, m1 - m2]); Give three pairs of pixel values (x, y) = [?, ?, ?] and (x+1, y) = [?, ?, ?] in the input image, for...
in C++ programing language Write a program that prompts the user for an integer, then prints...
in C++ programing language Write a program that prompts the user for an integer, then prints all of the numbers from one to that integer, separated by spaces. Use a loop to print the numbers. But for multiples of three, print "Fizz" instead of the number, and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz". Drop to a new line after printing each 20 numbers. If the user typed...
Assembly Language Programming Construct an assembly language program fragment equivalent to the following C/C++ statement: if...
Assembly Language Programming Construct an assembly language program fragment equivalent to the following C/C++ statement: if (M <= N + 3 && (C == ‘N’ || C == ‘n’)) C = ‘0’; else C = ‘1’; Assume that M and N are 32-bit signed integer variables, and C is an 8-bit ASCII character variable. All variables are stored in memory, and all general-purpose registers are available for use.
Java language (a) Write code segments to perform the following: (i) declare and create an integer...
Java language (a) Write code segments to perform the following: (i) declare and create an integer array freqArray of size 8 (ii) declare and initialize an array weight (with suitable type) which contains 48.5, 80 and 68 (iii) declare a Mouse array of size 2 with name mouse and initialize it with Mouse objects using one statement (b) A incomplete definition of a class Temperature is given below: public class Temperature { private double value[] = {36.5, 40, 37, 38.3};...
a) Write C code using a struct to hold student information: integer id integer number of...
a) Write C code using a struct to hold student information: integer id integer number of hours taken integer number of hours passed double gpa b) create a variable of the type in #25 and initialize it with some data.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT