0% found this document useful (0 votes)
4 views

Mid bank -1-small question answers

The document covers fundamental concepts in programming, including definitions of algorithms, flowcharts, and various programming constructs in C language. It discusses variable naming rules, input/output functions, branching statements, and differences between logical and bitwise operators. Additionally, it explains time and space complexity, type conversion vs. type casting, and provides syntax and flowcharts for control structures like if-else, loops, and switch statements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Mid bank -1-small question answers

The document covers fundamental concepts in programming, including definitions of algorithms, flowcharts, and various programming constructs in C language. It discusses variable naming rules, input/output functions, branching statements, and differences between logical and bitwise operators. Additionally, it explains time and space complexity, type conversion vs. type casting, and provides syntax and flowcharts for control structures like if-else, loops, and switch statements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

UNIT-1

1. **Define Algorithm? (K1)**


An algorithm is a finite set of well-defined instructions designed to solve a particular
problem. It outlines a step-by-step process for computations, starting with inputs and moving
towards desired outputs. For example, an algorithm to add two numbers might include steps
to take input, add the numbers, and output the result.

2. **Define Flowchart? (K1)**


A flowchart is a diagrammatic representation of an algorithm, showing the flow of
operations using standardized symbols. Common symbols include rectangles (for
processes), diamonds (for decision-making), and arrows (for flow direction). It helps visualize
and simplify the logic of a system.

3. **List out the rules to define the variables in C Language? (K2)**


- Variable names must begin with a letter or an underscore (`_`).
- The name can contain letters, digits, and underscores, but no other symbols or spaces.
- Variable names are case-sensitive, so `var` and `Var` are different.
- You cannot use C keywords like `int`, `return`, etc., as variable names.
- Names should be meaningful and ideally represent the purpose of the variable (e.g.,
`age`, `totalMarks`).

4. **Write a flowchart for the largest of two numbers. (K2)**


Refer notes

5. **Write any two unformatted I/O functions with syntax? (K2)**


- getchar(); – This function reads a single character from the standard input (usually
keyboard).
Example:
char ch = getchar();

- putchar(char); – This function writes a single character to the standard output (usually
console).
Example:
putchar('A');

6. **Write the basic input and output functions used in C with syntax? (K1)**
- **Input Function (scanf())**: Used to take input from the user.
Syntax:

scanf("%d", &var); // For integer input

- **Output Function (printf())**: Used to print output to the console.


Syntax:

printf("Value: %d", var); // To print integer value


7. **What is the difference between logical and bitwise operators? (K2)**

- **Logical Operators**: Used in conditional expressions that return either `true` or `false`.

Examples include `&&` (logical AND), `||` (logical OR), and `!` (logical NOT). They work on
boolean expressions.

- **Bitwise Operators**: Perform operations at the bit level.

Examples include `&` (bitwise AND), `|` (bitwise OR), `^` (bitwise XOR), and `~` (bitwise
NOT). These operate directly on the binary representations of integers.

8. **Write the difference between top-down and bottom-up approach? (K2)**


- **Top-down Approach**: The system is broken down from the main module into smaller
sub-modules or components. It focuses on high-level design first. For example, in structured
programming, the main function calls smaller functions.
- **Bottom-up Approach**: The system is developed by creating small components or
modules first, which are then integrated to form the whole system. It is used in
object-oriented programming, where small objects are created and then combined.

9. **Define Space Complexity? (K1)**


Space complexity is the measure of the amount of memory an algorithm requires relative
to the input size. It includes the memory used by variables, data structures, and call stack.
For example, an algorithm with space complexity `O(n)` uses memory that grows linearly
with input size.

10. **Define Compiler? (K1)**


A compiler is a software program that translates high-level source code (like C, Java) into
machine code (binary form) so that the program can be executed by a computer.

11. **What is the difference between type conversion and type casting? (K2)**
- **Type Conversion**: This is an automatic process done by the compiler, where data
types are implicitly converted to a larger or compatible data type (e.g., converting an `int` to
`float`).
- **Type Casting**: This is an explicit conversion done by the programmer to change one
data type to another (e.g., casting a `float` to `int` using `(int)`).

12. **Define Time Complexity? (K1)**


Time complexity refers to the amount of time an algorithm takes to run as a function of the
input size. It is expressed in terms of Big-O notation, such as `O(n)` for linear complexity or
`O(log n)` for logarithmic complexity.

---
Unit 2

1. **List different branching statements? (K1)**


- **if**: Executes a block of code if a specified condition is true.
- **if-else**: Executes one block if a condition is true, and another block if the condition is
false.
- **switch**: Allows the selection of multiple blocks of code to execute based on the value
of a variable.

2. **What is the difference between while and do-while? (K2)**


- **while**: The condition is checked before the loop body executes. If the condition is false
initially, the loop body never executes.
- **do-while**: The loop body is executed at least once, and the condition is checked after
the body has executed.

3. **What is the difference between break and continue? (K2)**


- **break**: Exits the nearest enclosing loop or switch statement entirely.
- **continue**: Skips the current iteration of the loop and moves to the next iteration without
exiting the loop.

4. **Write the syntax and flowchart of if-else statement? (K2)**


- Syntax:

if (condition) {
// statements
} else {
// statements
}

- **Flowchart**:
-refer class notes

5. **Write the syntax and flowchart of else-if ladder statement? (K2)**


- Syntax:

if (condition1) {
// statements
} else if (condition2) {
// statements
} else {
// statements
}

- **Flowchart**:
- refer class notes

6. **Write the syntax and flowchart of do-while loop? (K2)**


- Syntax:

do {
// statements
} while (condition);
- **Flowchart**:
- refer class notes

7. **Write the syntax and flowchart of for loop? (K2)**


- Syntax:

for (initialization; condition; increment) {


// statements
}

- **Flowchart**:
-refer class notes

8. **List different unconditional statements? (K1)**


- **break**: Exits from loops or switch-case.
- **continue**: Skips the current iteration of a loop.
- **goto**: Jumps to a labeled statement within the same function.
- **exit()**: Exits from a function and returns a value.

9. **Write the syntax and flowchart of switch? (K2)**


- Syntax:

switch (expression) {
case constant1:
// statements
break;
case constant2:
// statements
break;
default:
// statements
}

- **Flowchart**:
- refer class notes

10. **Write the syntax and flowchart of while loop? (K2)**


- Syntax:

while (condition) {
// statements
}

- **Flowchart**:
- refer class notes

11. **Write a C program to swap two numbers using a third variable. (K3)**
#include <stdio.h>
int main() {
int a, b, temp;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
temp = a;
a = b;
b = temp;
printf("After swapping: a = %d, b = %d", a, b);
return 0;
}

You might also like