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</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</p> Signup and view all the answers

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

    <p>Recursion</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</p> Signup and view all the answers

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

    <p>File Operations</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.</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.</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.</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.</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.</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</p> Signup and view all the answers

    What does the if statement in the second program check?

    <p>Whether x is greater than y</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.</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</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</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</p> Signup and view all the answers

    What is the main purpose of the programs described?

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

    What is the last thing executed in both programs?

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

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

    <p>int</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)}$</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</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.</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</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</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;</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.</p> Signup and view all the answers

    Which condition indicates a leap year?

    <p>The year is divisible by 100 and by 400.</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.</p> Signup and view all the answers

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

    <p>%</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.</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.</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</p> Signup and view all the answers

    Which step is NOT included in the leap year algorithm?

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

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

    <p>printf</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.</p> Signup and view all the answers

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

    <p>Modulus operator.</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.</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.</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.</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.</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.</p> Signup and view all the answers

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

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

    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

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