Basic Mathematics and C Programming Quiz
16 Questions
4 Views

Basic Mathematics and C Programming Quiz

Created by
@StatelyEpilogue7129

Podcast Beta

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What characteristic defines co-prime numbers?

  • They are always even numbers.
  • They have a common factor greater than 1.
  • They only have 1 as their common factor. (correct)
  • They have multiple common factors.
  • What is the area calculation formula for a right-angled triangle given base and height?

  • Base + Height
  • Base x Height
  • Base / Height
  • ½ x Base x Height (correct)
  • Which type of memory is the fastest in a computer?

  • Hard Disk
  • Virtual Memory
  • RAM
  • Cache Memory (correct)
  • When converting from Gray code to BCD, what is a necessary step?

    <p>Calculating the decimal equivalence.</p> Signup and view all the answers

    How is the billing calculated for the first 100 electricity units consumed?

    <p>INR 250.00 for the first 100 units.</p> Signup and view all the answers

    What determines if three sides can form a triangle?

    <p>The sum of any two sides must be greater than the third side.</p> Signup and view all the answers

    What is the maximum number of variables allowed in the C program to swap two numbers using the comma operator?

    <p>3</p> Signup and view all the answers

    What is the billing rate for units consumed above 800 in the electricity billing system?

    <p>INR 6.00 per unit</p> Signup and view all the answers

    What are the values of m and n after executing the code snippet?```c int i=10, m,n; m=i--; n = ++i + i;

    <p>m = 9, n = 20</p> Signup and view all the answers

    Which of the following is NOT a bitwise operator in C?

    <p>-&gt; (Pointer Dereference)</p> Signup and view all the answers

    What is the output of the following code snippet?```c main() { int i=2, j=3, z; printf("%d ", i - ++j); }

    <p>-1</p> Signup and view all the answers

    If 53/4 = 12 in a certain number system, what is the base of that number system?

    <p>8</p> Signup and view all the answers

    What is the output of the following code snippet?```c for(i=0; i=3; i++) { break; printf("Inside Loop %d", i); } printf("Outside Loop %d", i);

    <p>Outside Loop 0</p> Signup and view all the answers

    Which of the following is NOT a method for writing selection statements in C?

    <p>do-while loop</p> Signup and view all the answers

    What is the main difference between an interpreter and a compiler?

    <p>Compilers provide execution speed advantage over interpreters.</p> Signup and view all the answers

    In IEEE Double precision floating point representation, which component is used to store the exponent?

    <p>Exponent field</p> Signup and view all the answers

    Study Notes

    Introduction to Computing Exam Notes

    • The exam has 3 sections (Group A, Group B, Group C) and is worth 70 marks.
    • Students must write answers in their own words.
    • Non-programmable calculators are allowed.

    Group A: Multiple Choice Questions

    • 1.1: After executing the code, the value of m is 10 and the value of n is 22. Note the order of operations:
      • m=i-- assigns m the value of i (10) and then decrements i.
      • n = ++i + i increments i to 11, then adds i to itself, resulting in 22.
    • 1.2: Bitwise operators include:
      • AND (&)
      • OR (|)
      • XOR (^)
      • NOT (~)
    • 1.3: The code outputs: -1
      • The increment (++j) happens before the subtraction, setting j to 4.
      • i remains at 2, resulting in 2 - 4 = -1.
    • 1.4: The base of the number system is 13.
      • In base 13, 53 / 4 = 12 with a remainder of 1.
    • 1.5: The output of the code is “Outside Loop 3"
      • The break statement immediately exits the loop without executing any further steps.
    • 1.6:
      • Non-weighted code: BCD (Binary Coded Decimal)
      • Weighted code: 8421 BCD
      • Cyclic code: Gray Code
      • Self-complementing code: Excess-3 code
    • 1.7: Methods for writing selection statements in C include:
      • if-else statement
      • switch-case statement
      • Conditional operator (?:)
    • 1.8: The format of the ternary operator is: condition ? expression1 : expression2;
      • Example : x = (y > 0) ? y : -y
    • 1.9: Major differences between Linux and Windows Operating Systems:
      • Linux is open-source, while Windows is proprietary.
      • Linux is known for its stability and security, while Windows is user-friendly and has a wider range of applications.
    • 1.10: Special registers in a computer (Von Neumann Architecture) include:
      • Program Counter (PC)
      • Memory Address Register (MAR)
      • Memory Data Register (MDR)
      • Accumulator (ACC)
    • 1.11: The code output is: 4.250 2.000
      • z is calculated by first casting y to a floating-point type before division.
      • z1 is calculated by casting x to an integer before division.
    • 1.12: The structure of the switch-case construct in C language is:
      switch (expression){
           case value1:
              // statements to execute
              break;
           case value2:
              // statements to execute
              break;
           default:
              // statements to execute
              break;
      } 
      
      • Example:
      switch (day){
      case 1:
          printf("Monday");
          break;
      case 2:
          printf("Tuesday");
          break;
      default:
          printf("Other day");
          break;
      }
      

    Group B: Short Answer Questions

    • Q 2: To represent (50.25)10 in IEEE Double precision floating point number representation:
      • Step 1: Convert the decimal number to binary
        • Integer part: (50)10 = (110010)2
        • Fractional part: (0.25)10 = (0.01)2
      • Step 2: Combine the integer and fractional parts: (50.25)10 = (110010.01)2
      • Step 3: Normalize the binary number: (1.1001001)2 * 2^5
      • Step 4: Represent the sign, exponent, and mantissa in IEEE Double precision format:
        • Sign bit: 0 (positive number)
        • Exponent: 5 + 1023 = 1028 = (10000001000)2
        • Mantissa: (1001001 00000000000000000000000000000000000000000000)2
      • Step 5: Combine the sign, exponent, and mantissa:
        • (0 10000001000 1001001 00000000000000000000000000000000000000000000)2
    • Q 3: Explanation of the Memory Unit in Von Neumann Architecture:
      • Diagram: A diagram with components like:
        • Memory Address Register (MAR): Holds the address of the location being accessed.
        • Memory Data Register (MDR): Holds the data being read from or written to memory.
        • Memory Unit: Stores data and instructions.
        • Control Unit: Directs data flow between the memory and other components.
        • ALU (Arithmetic Logic Unit): Performs arithmetic and logical operations on data.
        • Registers: Temporary storage locations for immediate data access.
      • Explanation:
        • The Memory Unit is a central component that stores both data and instructions.
        • MAR holds the address of the location to be accessed.
        • MDR stores the actual data being read or written to memory.
        • The control unit manages data flow by sending address information to MAR and transferring data from MDR to registers.
        • The ALU process data according to the instructions retrieved from memory.
        • Registers provide faster access to frequently used data.
    • Q 4:
      • Assembler: Translates assembly language (low-level programming language) into machine code (binary instructions).
        • Example: Assembler translating assembly code for adding two numbers into a binary instruction.
      • Interpreter: Executes each line of code directly without generating an intermediate machine code file.
        • Example: Python interpreter executing each line of Python code one by one.
      • Compiler: Translates a high-level programming language like C into machine code, producing an executable file for the target platform.
        • Example: A C compiler translating a C program into an executable file on a Windows machine.
      • Why is C called a functional programming language?: C is generally considered a procedural or imperative programming language, not a functional programming language.
        • Procedural languages focus on a sequence of steps to achieve a result, emphasizing control flow and data structures.
        • Functional languages utilize functions as first-class citizens, emphasizing immutability and recursion.
    • Q 5:
      • Step 1: Sender S generates even parity bits for the code 1100:
        • 1100 (Data bits)
        • 0 (Parity bit added)
        • 11000 (Codeword with parity bit)
      • Step 2: Receiver R receives code 1000 and calculates the parity bit:
        • 1000 (Received code)
        • 1 (Parity bit calculated)
      • Step 3: The calculated parity bit is not the same as the received parity bit, indicating an error.
      • Step 4: R uses Hamming code to detect the error position:
        • 1000 (Received data)
        • XOR with 0100 (2^2 = 4)
        • 1100 (Resulting code)
      • Step 5: Error detected at position 2.
    • Q 6:
      • Algorithm:
        • Input: Two integers, num1 and num2
        • Output: True if numbers are co-prime, False otherwise
        • Steps:
          • If both numbers are equal to zero then return False
          • Find the greatest common divisor (GCD) of the two numbers.
          • If GCD is 1, then the numbers are co-prime, return True
          • Otherwise, the numbers are not co-prime, return False.
      • Pseudocode:
      function are_coprime (num1, num2):
          if num1 == 0 and num2 == 0:
              return False
          gcd = calculate_gcd(num, num2)
          if gcd == 1:
              return True
          else:
              return False
      
      • Convert Gray code 10100 to BCD code:
        • Step 1: Convert each bit of the Gray code to BCD code one at a time.
          • 1 (Gray) = 0001 (BCD)
          • 0 (Gray) = 0000 (BCD)
          • 1 (Gray) = 0001 (BCD)
          • 0 (Gray) = 0000 (BCD)
          • 0 (Gray) = 0000 (BCD)
        • Step 2: Combine the individual BCD values: (10100)Gray = (0001 0000 0001 0000 0000)BCD.
        • Number of bits in the BCD code: 20.

    Group C: Long Answer Questions

    • Q 7:

      • 7.(a) C program to check for a right-angled triangle:
        #include <stdio.h>
        #include <math.h>
        
        int main() {
            int a, b, c;
            float area;
        
            printf ("Enter three sides of the triangle (in non-descending order): ");
            scanf ("%d %d %d", &a, &b, &c);
        
            // check if triangle is possible
            if (a + b > c) { // Triangle inequality theorem
                if (a * a + b * b == c * c) { // Checking Pythagoras Theorem for right-angled triangle
                    printf("Right-angled triangle.\n");
                    area = 0.5 * a * b; // calculating area in case of right-angled triangle
                    printf("Area of the triangle: %.2f\n", area);
                } else {
                    printf("Not a right-angled triangle.\n");
                }
            } else { 
                printf("Not a valid triangle.\n");
            }
        
            return 0;
        }
        
      • 7.(b) Types of memory in a computer (in descending order of speed):
        • Registers: Fastest memory, directly accessible by the CPU.
        • Cache memory: High-speed, temporary storage for frequently used data.
        • Main memory (RAM): Primary storage for active data and instructions.
        • Secondary storage: Slower, long-term storage devices like hard drives, SSDs, and optical drives.
    • Q 8:

      • 8.(a) C program to swap two numbers using the comma operator:
        #include<stdio.h>
        int main () {
            int a = 10, b = 20, temp; 
            printf ("Original Values: a = %d , b = %d\n", a, b);
            temp = a, a = b, b = temp; // Comma operator is used to complete a series of operations
            printf ("Values after swapping: a = %d , b = %d\n", a, b);
            return 0;
        }
        
      • 8.(b) Conversions:
        • (10100)Gray = (2101)4 = (451)6
          • Gray to binary conversion: 10100 -> 11011
          • Binary to base 4 by grouping bits into twos: 11 01 11 -> 2 1 0 1
          • Binary to base 6 by grouping bits in threes: 11 01 1 -> 3 1 1 -> 4 5 1
        • (25.025)10 = (0010 0101.0000 0010 0101)BCD = (11001.000001)2
          • Each decimal digit of the number is converted into its 4-bit BCD equivalent.
        • (771)8 = (505)10 = (20211)4
          • Octal to decimal: (771)8 = (7 * 8^2) + (7 * 8^1) + (1 * 8^0) = (505)10
          • Decimal to base 4: (505)10 = (2^9) + (2^8) + (2^4) + (2^0) = (20201)4.
    • Q 9:

      • Definition: An Operating System is a program or collection of programs that manages and controls the computer's hardware and software resources.
      • Main Functions:
        • Memory Management: Allocate and manage memory effectively.
        • Process Management: Create, schedule, and terminate processes efficiently.
        • File Management: Organize and manage files, directories, and storage.
        • Device Management: Manage and control peripheral devices connected to the computer.
        • Security: Protect the system from unauthorized access and malicious attacks.
        • Interface: Provide a user-friendly interface for interacting with the computer.
      • Types of OS:
        • Real-time Operating Systems (RTOS): Designed for real-time applications with strict timing requirements.
        • Multi-user Operating Systems: Allow multiple users to access and utilize the system simultaneously.
        • Multitasking Operating Systems: Allow multiple tasks or programs to run concurrently.
        • Single-user Operating Systems: Allow only one user to access the system at a time.
        • Distributed Operating Systems: Spread across multiple computers, enabling resource sharing and communication between nodes.
    • Q 10:

      • 10. (a) Flowchart for calculating electricity bill:
        • Start:
        • Input: Total units consumed
        • Calculate Base Slab Charges:
          • If units < 100, then bill = 250
          • Else if units <= 200, then bill = 250 + (units - 100) * 3
          • Else if units <= 500, then bill = 250 + (100 * 3) + (units - 200) * 4
          • Else if units <= 800, then bill = 250 + (100 * 3) + (300 * 4) + (units - 500) * 5
          • Else, bill = 250 + (100 * 3) + (300 * 4) + (300 * 5) + (units - 800) * 6
        • Output: bill
        • End:
        • The flowchart should visually represent the steps outlined above, using symbols for decisions (diamond), processes (rectangles), and input/output (parallelograms).

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Related Documents

    Description

    Test your knowledge of basic mathematics concepts and C programming! This quiz covers topics ranging from co-prime numbers to memory types in computers. Sharpen your skills in both areas with this engaging set of questions.

    More Like This

    Use Quizgecko on...
    Browser
    Browser