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

Computer_Science_Assignment_Solved

The document provides an overview of C programming concepts, including classifications of constants, types of instructions, flow-chart creation for simple interest, and algorithms such as the Fibonacci series. It also explains logical operators, the purpose of loops, differences between while and do-while loops, and the use of break and continue statements. Additionally, it lists common header files used in C programming.

Uploaded by

kararpita814
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)
6 views

Computer_Science_Assignment_Solved

The document provides an overview of C programming concepts, including classifications of constants, types of instructions, flow-chart creation for simple interest, and algorithms such as the Fibonacci series. It also explains logical operators, the purpose of loops, differences between while and do-while loops, and the use of break and continue statements. Additionally, it lists common header files used in C programming.

Uploaded by

kararpita814
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/ 4

Computer Science Assignment

1. Give the classification of 'C' constants.

C constants are classified into the following categories:

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

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

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

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

2. Write down different C instructions (Describe).

C instructions are classified into three types:

1. **Type Declaration Instructions:** Used to declare variables (e.g., int, float).

2. **Arithmetic Instructions:** Used to perform operations (e.g., +, -, *, /).

3. **Control Instructions:** Used to control the flow of the program (e.g., if, for, while).

3. Draw the flow-chart of the program which creates the Simple Interest.

The flow-chart involves the following steps:

1. Start

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

3. Calculate Simple Interest: SI = (P × R × T) / 100.

4. Output the result.

5. End.

4. What is Algorithm? Write an algorithm for the program of the Fibonacci Series.

An algorithm is a step-by-step procedure or formula for solving a problem.

**Algorithm for Fibonacci Series:**

1. Start

2. Input the number of terms (n).


3. Initialize a = 0, b = 1.

4. Print a, b.

5. Repeat until n terms:

a. c = a + b

b. Print c

c. Update a = b, b = c

6. End.

5. What do you mean by logical operators?

Logical operators are used to perform logical operations in C:

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

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

3. **NOT (!):** Reverses the logical state.

6. Why Loop is used?

Loops are used to repeat a set of instructions until a condition is met. This reduces code

redundancy and makes programs efficient.

7. What are the different types of loops?

The main types of loops in C are:

1. **for loop:** Used when the number of iterations is known.

2. **while loop:** Used when the condition is checked before the loop starts.

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

8. What are the differences between while loop and do-while loop?

**while loop:**

- Checks the condition before execution.

- May not execute if the condition is false initially.

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

- Checks the condition after execution.

9. Why break statement is used? Give example.

The break statement is used to exit from a loop or switch statement before it completes its normal

iteration.

**Example:**

```

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

if (i == 5) break;

printf("%d ", i);

```

10. Why continue is used? Give example.

The continue statement is used to skip the current iteration of a loop and continue with the next

iteration.

**Example:**

```

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

if (i == 5) continue;

printf("%d ", i);

```

11. What are the different types of header files used in C programs?

Header files contain function declarations and macro definitions for libraries. Common header files

include:
1. **stdio.h:** For input/output functions (e.g., printf, scanf).

2. **stdlib.h:** For standard library functions (e.g., malloc, free).

3. **math.h:** For mathematical functions (e.g., sqrt, pow).

4. **string.h:** For string manipulation functions (e.g., strlen, strcpy).

You might also like