Programming Experiments Overview
45 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What is the purpose of the first experiment listed in the index?

  • To find the factorial of a given number
  • To display values using data types (correct)
  • To check for leap years
  • To implement decision-making constructs
  • Which of the following data types is NOT mentioned in the experiment related to I/O statements?

  • Int
  • Double (correct)
  • Float
  • Char
  • Which algorithm step comes directly after declaring variables in the first experiment?

  • Stop the program
  • Start the program
  • Display the values using data types
  • Get the values using the data types (correct)
  • In how many experiments are functions utilized according to the index?

    <p>7 (B)</p> Signup and view all the answers

    Which experiment is directly related to analyzing numerical properties of a number?

    <p>Finding Factorial of a given Number (B)</p> Signup and view all the answers

    What concept does the 'Towers of Hanoi using Recursion' experiment primarily illustrate?

    <p>Recursion (C)</p> Signup and view all the answers

    What task is performed in the experiment 'Find the Length of the string without using library function'?

    <p>Calculate the number of characters in a string (C)</p> Signup and view all the answers

    Which of the following operations is related to handling data in structured formats?

    <p>File Operations (D)</p> Signup and view all the answers

    What will happen if the divisor in the division operation is zero?

    <p>An error message will be printed. (C)</p> Signup and view all the answers

    What is the purpose of the case labeled '5' in the switch statement?

    <p>To find the square of a given number. (D)</p> Signup and view all the answers

    How does the program determine if a number is invalid?

    <p>By defaulting to a message when an unexpected choice is made. (A)</p> Signup and view all the answers

    In the multiplication case of the switch statement, how are the numbers read?

    <p>Two floating-point numbers are read as inputs. (B)</p> Signup and view all the answers

    Which of the following statements about the algorithm for checking an Armstrong number is true?

    <p>It verifies the number using its digits raised to the power of the number of digits. (D)</p> Signup and view all the answers

    What is the output when the input number is 0 in the first program?

    <p>Number is ZERO (C)</p> Signup and view all the answers

    What does the if statement in the second program check?

    <p>Whether x is greater than y (C)</p> Signup and view all the answers

    Which of the following is true about the nested if-else statement in the program for three numbers?

    <p>It allows for a sequence of comparisons. (B)</p> Signup and view all the answers

    What would be printed if x is 5 and y is 5 in the second program?

    <p>x and y are Equal (D)</p> Signup and view all the answers

    If the user enters -10 in the first program, what will the output be?

    <p>Number is NEGATIVE (C)</p> Signup and view all the answers

    In the second program, what condition leads to the output 'y is Greater'?

    <p>x is less than y (A)</p> Signup and view all the answers

    What is the main purpose of the programs described?

    <p>To show decision making using if statements (A)</p> Signup and view all the answers

    What is the last thing executed in both programs?

    <p>A return statement (D)</p> Signup and view all the answers

    What data type is used to store the integer value in the given C program?

    <p>int (C)</p> Signup and view all the answers

    Which formula is used to calculate the area of a triangle in the provided program?

    <p>$A = \sqrt{s(s-a)(s-b)(s-c)}$ (A)</p> Signup and view all the answers

    What will be the output when the user enters '0' for the integer input in the program checking for positive, negative, or zero?

    <p>Number is ZERO (C)</p> Signup and view all the answers

    Which statement correctly describes the input for the sides of the triangle in the program calculating the area?

    <p>The input should be three integers. (C)</p> Signup and view all the answers

    In the triangle area calculation program, what type of value does 's' represent?

    <p>The semi-perimeter of the triangle (D)</p> Signup and view all the answers

    What is a common mistake when trying to input a string into the 'svar' variable in the I/O program?

    <p>Using scanf incorrectly for strings (C)</p> Signup and view all the answers

    What should be included in the C program to perform sqrt calculations?

    <p>#include &lt;math.h&gt; (C)</p> Signup and view all the answers

    Which of the following best describes the control flow used to check if a number is positive, negative, or zero?

    <p>Multiple nested if statements check each case sequentially. (B)</p> Signup and view all the answers

    Which condition indicates a leap year?

    <p>The year is divisible by 100 and by 400. (B), The year is divisible by 4 and not divisible by 100. (C)</p> Signup and view all the answers

    What will the program output if the input year is 1900?

    <p>The Given year 1900 is Not a Leap Year. (C)</p> Signup and view all the answers

    In the leap year program, which operator is used to check if the year is even?

    <p>% (B)</p> Signup and view all the answers

    What should the program do if the user selects division and the divisor is zero?

    <p>Display an error message for division by zero. (D)</p> Signup and view all the answers

    What is the purpose of the step that checks if the user input for operation corresponds to the defined choices?

    <p>To ensure valid input is used for calculations. (B)</p> Signup and view all the answers

    What data type is used for storing the result of the arithmetic operations in the calculator program?

    <p>float (B)</p> Signup and view all the answers

    Which step is NOT included in the leap year algorithm?

    <p>Multiplying the year by two. (A)</p> Signup and view all the answers

    Which C function is used to output text to the user?

    <p>printf (D)</p> Signup and view all the answers

    What is the purpose of the program checking for a three-digit integer?

    <p>To determine if the number is an Armstrong number. (D)</p> Signup and view all the answers

    In the Armstrong number calculation, what operation is performed to isolate the last digit?

    <p>Modulus operator. (A)</p> Signup and view all the answers

    What will happen if a number less than 100 or greater than 999 is entered into the Armstrong program?

    <p>The program will terminate with an error message. (D)</p> Signup and view all the answers

    Which part of the program determines if a number is odd or even?

    <p>The program checks if the number is divisible by 2. (C)</p> Signup and view all the answers

    What will the output be if the user inputs the number 4 in the even or odd program?

    <p>4 is an Even number. (B)</p> Signup and view all the answers

    What is the output after successfully completing the Armstrong program with the input 153?

    <p>153 is an Armstrong number. (D)</p> Signup and view all the answers

    What could be a reason for a user to see 'It is an Odd Number' as output?

    <p>The input was not divisible by 2. (A)</p> Signup and view all the answers

    Which variable in the Armstrong program keeps track of the calculated result?

    <p>result (A)</p> Signup and view all the answers

    Flashcards

    String

    A sequence of characters used to represent text.

    Integer

    A data type used to store whole numbers (integers).

    Float

    A data type used to store numbers with decimal points.

    Character

    A data type used to store a single character, like a letter or symbol.

    Signup and view all the flashcards

    Input Statement

    A tool in programming that allows you to get input from the user.

    Signup and view all the flashcards

    Output Statement

    A tool in programming that displays information to the user.

    Signup and view all the flashcards

    Expression

    A combination of variables, operators, and constants that produce a value.

    Signup and view all the flashcards

    Declaration

    The process of storing data in a computer's memory.

    Signup and view all the flashcards

    What is a character data type in C?

    A data type in C that represents characters and can be used to store text.

    Signup and view all the flashcards

    What is the purpose of the scanf function in C?

    The scanf function is used to input data (like integers, floats, or strings) from the user.

    Signup and view all the flashcards

    What is the purpose of the printf function in C?

    The printf function is used to display output on the console, such as showing the values of variables or messages.

    Signup and view all the flashcards

    What is Heron's formula?

    A formula used to calculate the area of a triangle using its sides (a, b, c) and semi-perimeter (s), where s = (a + b + c)/2.

    Signup and view all the flashcards

    What is the purpose of the sqrt function in C?

    The sqrt function in C is used to calculate the square root of a number.

    Signup and view all the flashcards

    What is a conditional statement in C?

    In C, conditional statements execute different blocks of code based on whether a certain condition is true or false. The most common conditional statement is the if statement.

    Signup and view all the flashcards

    What does the %d format specifier mean in C?

    The %d format specifier in C is used for printing integer values.

    Signup and view all the flashcards

    What does the %f format specifier mean in C?

    The %f format specifier in C is used for printing floating-point numbers.

    Signup and view all the flashcards

    Program

    A set of instructions that tell a computer what to do.

    Signup and view all the flashcards

    Leap Year Rules

    A year is a leap year if it is divisible by 4, but not by 100, unless it is also divisible by 400.

    Signup and view all the flashcards

    Modulo Operator (%)

    The % operator in C calculates the remainder of a division.

    Signup and view all the flashcards

    Conditional Statement (if)

    The if statement in C allows you to execute different code blocks based on a condition.

    Signup and view all the flashcards

    Input Function (scanf)

    The scanf function in C reads data from the user and stores it in variables.

    Signup and view all the flashcards

    Output Function (printf)

    The printf function in C displays output on the console.

    Signup and view all the flashcards

    Leap Year Program (C)

    A C program to find the Leap year takes an input year from the user and calculates whether it is a leap year based on rules. It uses conditional statements to determine the leap year status.

    Signup and view all the flashcards

    Logical AND Operator (&&)

    The && operator in C combines two conditions and returns true only if both conditions are true.

    Signup and view all the flashcards

    Logical OR Operator (||)

    The || operator in C combines two conditions and returns true if at least one of the conditions is true.

    Signup and view all the flashcards

    What is a switch statement?

    A switch statement is a control flow statement that allows a program to execute different blocks of code based on the value of an expression.

    Signup and view all the flashcards

    What is the purpose of the case keyword?

    The case keyword is used in switch statements to mark different blocks of code that run based on the value of the variable being checked.

    Signup and view all the flashcards

    What is the purpose of the default keyword in a switch statement?

    The default keyword is used in switch statements to provide a block of code that runs if no other case matches the value being checked.

    Signup and view all the flashcards

    What is the purpose of the break keyword in a switch statement?

    The break keyword is used to exit a switch statement after a case has been executed.

    Signup and view all the flashcards

    What is the advantage of using a switch statement over multiple if-else statements?

    A switch statement is used to choose from a limited number of options, making it faster and more efficient than using a chain of if-else statements.

    Signup and view all the flashcards

    If Statement

    A control flow statement that allows the program to execute a block of code only if a certain condition is true. If the condition is false, the code block is skipped.

    Signup and view all the flashcards

    While Loop

    A type of loop that continues to execute a block of code as long as a certain condition is true. Once the condition becomes false, the loop ends.

    Signup and view all the flashcards

    Digit Extraction

    A process in programming that takes a number and repeatedly divides it by 10 until it becomes 0. Each time, the remainder is stored, which represents the last digit of the original number.

    Signup and view all the flashcards

    Armstrong Number

    A number that is equal to the sum of the cubes of its digits.

    Signup and view all the flashcards

    Study Notes

    Course Information

    • Institution: Sai Ram Engineering College
    • Department: Mechanical Engineering
    • Batch: 2024-2028
    • Semester: First Semester
    • Course: Programming in C Laboratory
    • Academic Year: 2024-2025
    • Course Code: 24ESPL101

    Laboratory Experiments

    • Experiment 1: I/O statements and expressions

      • Aim: Write a C program to display the values using data types.
      • Algorithm:
        • Start the program
        • Declare variables (int, float, char).
        • Get input values for each data type.
        • Display the values using printf().
        • End the program
      • Program Code: Includes the necessary header file, declares variables, prompts the user to input integer, float and string values using printf, stores the input using scanf, prints the respective values using printf.
    • Experiment 2: Programs using decision-making constructs (Positive, negative or zero)

      • Aim: Write a C program to check if a number is positive, negative, or zero using an if statement.
      • Algorithm:
        • Start the program
        • Declare an integer variable.
        • Get input from the user
        • Check if the number is >0, <0, or =0 using if-else statements
        • Print the result (POSITIVE, NEGATIVE, or ZERO)
        • End the program
      • Program: Includes header file, declares and initializes variables. Gets input using printf and scanf. Uses an if-else ladder structure to check and print appropriate results
    • Experiment 3: Greatest among two numbers

      • Aim: Write a C program to find the largest of two numbers using if-else.
      • Algorithm:
        • Start the program
        • Declare two integer variables.
        • Get input for the two numbers from the user.
        • Compare the two numbers using if-else.
        • Print the largest number.
        • End the program.
    • Experiment 4: Greatest among three numbers

      • Aim: Write a C program to find the largest of three numbers using nested if-else statements.
      • Algorithm:
        • Start the program.
        • Declare three integer variables (a, b, c).
        • Input the three numbers from the user.
        • Use nested if-else to compare the numbers and determine the largest.
        • Print the largest number.
        • End the program.
    • Experiment 5 : Check if a number is divisible by both 5 and 8

      • Aim: Check if an input number is divisible by both 5 & 8 using else if ladder.
      • Algorithm:
        • Start the program
        • Input a number from the user
        • Check if the number is divisible by 5 and 8
        • Print appropriate message ('Divisible by both 5 and 8', 'Divisible by 8', 'Divisible by 5', 'Divisible by none')
        • End the program
    • Experiment 6: Check for leap year

      • Aim: Determine if a given year is a leap year.
      • Algorithm:
        • Input year from the user
        • Check if the year is divisible by 4, but not 100, or it is divisible by 400.
        • Print message ('Leap year' or 'Not leap year').
    • Experiment 7: Simple Arithmetic Calculator

      • Aim: Develop a C program to perform basic calculator operations.
      • Algorithm:
        • Display a menu (options for addition, subtraction, multiplication, division, and square)
        • Prompt user input for operation choice
        • Implement appropriate calculations by taking the input 2 numbers, as per choosen operation.
        • Display the result.
    • Experiment 8: Find the factorial of a given number

      • Aim: Calculate the factorial of a number.
      • Algorithm:
        • Accept input (integer)
        • Check input validation.
        • Calculate the factorial using a loop
        • Present output: Factorial (of the input)
    • Experiment 9: Find the average of 4 given numbers

      • Aim: Compute the average of 4 input numbers.
      • Algorithm:
        • Take input for 4 numbers
        • Calculate the sum
        • Calculate the average by dividing the sum of 4 input numbers.
        • Present output
    • Experiment 10: Display array elements using two-dimensional arrays

      • Aim: Display elements of a 2-dimentional array.
      • Algorithm:
        • Declare a 2-dimensional array.
        • Accept input for the array elements
        • Print all elements of the array in a formatted way
    • Experiment 11: Perform swapping using a function

      • Aim: Write C program to swap two numbers by using a separate function.
      • Algorithm:
        • Input two numbers.
        • Define a function swap to swap the numbers using pointers
        • Call the function swap to swap numbers.
        • Display swapped numbers.
    • Experiment 12: Generate Prime Numbers between two intervals using functions

      • Aim: Display prime numbers within a specified numeric range.
      • Algorithm:
      • Accept input for the range (n1 and n2).
      • Check if each number within the range is prime.
      • Define a function to check primality.
      • Present output (list of primes).
    • Experiment 13: Solve Towers of Hanoi using recursion

      • Aim: Create a recursive program for the Tower of Hanoi puzzle.
      • Algorithm:
      • The problem is solved by applying a recursive algorithm. Each step and the required calls to other functions and the basic logic are in the algorithm.
    • Experiment 14: Get the largest element of an array using functions

      • Aim: Find and display largest element in an array.
      • Algorithm:
        • Get size of the array
        • Accept array elements.
        • Define a function to determine the maximum element.
        • Print the result (the maximum value).
    • Experiment 15: Concatenate two strings

      • Aim: Append (concatenate) two strings.
      • Algorithm:
        • Input two strings
        • Calculate length of first string
        • Copy characters of second string to the end of first string
        • Print the output
    • Experiment 16: Find the length of a string

      • Aim: Measure the length of a given string.
      • Algorithm:
      • Get an input string from the user
      • Count characters up to the null termination character (\0)
      • Display the string length.
    • Experiment 17: Find the frequency of a character in a string

      • Aim: Determine the frequency of a given character in a string
      • Algorithm:
        • Accepting string and target character
        • Comparing target character and all characters of string
        • Incrementing count accordingly
        • Display result
    • Experiment 18: Store and Display Student Information in a Structure

      • Aim: Create a structure of student data and display it.
      • Algorithm:
        • Declaring a Student structure with fields for name, roll number, and marks.
        • Input student data (name, roll number, and marks) using a loop
        • Display the filled structure for all students.
    • Experiment 19: Process Student Information using Structure

      • Aim: Compute total marks by student, highest subject scores, and highest overall marks.
      • Algorithm:
        • Creates student structure.
        • Accepts student data (name, roll number, marks in 3 subjects)
        • Calculates total marks for each student.
        • Determines highest marks in each subject and student who achieved it.
        • Determines the student with the highest overall marks.
    • Experiment 20: Demonstrate file operations

      • Aim: Perform file operations including character, word and lines counting and replacement of a word in the text file.
      • Algorithm:
      • Open the file for reading.
      • Initialization of counters for characters, words, and lines to 0.
      • Read all characters one by one
      • Count characters, words, and lines based on characters.
      • Close the file.
      • Open the file in write mode.
      • Replace specific words in file content and save.
      • Close the file.

    Studying That Suits You

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

    Quiz Team

    Related Documents

    Description

    This quiz covers various programming experiments related to I/O statements, algorithms, and function utilization. It addresses key concepts such as recursion, data types, and numerical properties. Test your knowledge on different programming tasks and the underlying principles behind them.

    More Like This

    Types and Method Overriding in Programming
    41 questions
    Programming Chapter 13 Flashcards
    40 questions
    Programming Languages Quiz
    27 questions
    Use Quizgecko on...
    Browser
    Browser