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

Computer_Assignment_Solutions_Part2

The document provides an overview of constants in C, classifying them into integer, floating-point, character, and string constants. It describes various C instructions, including type declaration, arithmetic, control, and input/output instructions, and outlines the flowchart for calculating simple interest. Additionally, it explains algorithms, logical operators, loop types, and the use of break and continue statements, along with header file types in C programming.

Uploaded by

kararpita814
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Computer_Assignment_Solutions_Part2

The document provides an overview of constants in C, classifying them into integer, floating-point, character, and string constants. It describes various C instructions, including type declaration, arithmetic, control, and input/output instructions, and outlines the flowchart for calculating simple interest. Additionally, it explains algorithms, logical operators, loop types, and the use of break and continue statements, along with header file types in C programming.

Uploaded by

kararpita814
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Computer Assignment Solutions - Part 2

4. Give the classification of 'C' constants.

- Constants are fixed values that cannot be altered during the execution of a program.

Classification:

1. **Integer Constants**: Whole numbers without fractions (e.g., 10, -20).

2. **Floating-point Constants**: Numbers with decimal points (e.g., 3.14).

3. **Character Constants**: Single characters enclosed in single quotes (e.g., 'A').

4. **String Constants**: Sequence of characters enclosed in double quotes (e.g., "Hello").

5. Write down different C instructions (describe).

C instructions are classified into:

1. **Type Declaration Instructions**: Declare variables and constants, e.g., `int a;`.

2. **Arithmetic Instructions**: Perform mathematical operations, e.g., `a = b + c;`.

3. **Control Instructions**: Control the flow of execution, e.g., `if`, `for`.

4. **Input/Output Instructions**: Handle I/O operations, e.g., `scanf()`, `printf()`.

6. Draw the flowchart of the program which creates the simple interest.

The flowchart would include the following steps:

1. Start.

2. Input Principal (P), Rate (R), and Time (T).

3. Calculate Simple Interest (SI) using SI = (P * R * T) / 100.

4. Output SI.

5. Stop.

Note: Flowchart diagrams are not included in this PDF.

7. What is Algorithm? Write an algorithm for the Fibonacci series.

- **Algorithm**: A step-by-step procedure to solve a problem in a finite number of steps.


Algorithm for Fibonacci series:

1. Start.

2. Input n (number of terms).

3. Initialize a = 0, b = 1.

4. Print a, b.

5. Repeat for i = 3 to n:

a. c = a + b.

b. Print c.

c. Update a = b, b = c.

6. Stop.

8. What do you mean by logical operators?

Logical operators are used to perform logical operations, commonly in decision-making.

- **AND (&&)**: Returns true if both conditions are true.

- **OR (||)**: Returns true if at least one condition is true.

- **NOT (!)**: Reverses the logical state of its operand.

9. Why is Loop used?

Loops are used to repeat a block of code multiple times until a specific condition is met, reducing

redundancy and enhancing efficiency.

10. What are the different types of loops?

The types of loops in C are:

1. **for loop**: Repeats a block of code a specific number of times.

2. **while loop**: Repeats code as long as a condition is true.

3. **do-while loop**: Similar to while but executes at least once before checking the condition.

11. What are the differences between while and do-while loops?

- **while loop**: Condition is checked before executing the loop body.


- **do-while loop**: Executes the loop body at least once before checking the condition.

12. Why is break statement used? Give example.

- The `break` statement is used to exit a loop or switch statement prematurely.

Example:

```c

for (int i = 1; i <= 10; i++) {

if (i == 5) break;

printf("%d ", i);

```

13. Why continue is used? Give example.

- The `continue` statement skips the rest of the loop body and proceeds to the next iteration.

Example:

```c

for (int i = 1; i <= 10; i++) {

if (i == 5) continue;

printf("%d ", i);

```

14. What are the different types of header files used in C program?

- Header files contain function declarations and macro definitions.

Types:

1. **Standard Header Files**: Provided by the C library (e.g., `stdio.h`, `math.h`).

2. **User-defined Header Files**: Created by programmers for specific needs.

Functions in Header Files:


- `stdio.h`: `printf()`, `scanf()`.

- `math.h`: `sqrt()`, `pow()`.

- `string.h`: `strlen()`, `strcpy()`.

You might also like