0% found this document useful (0 votes)
12 views3 pages

Short Note Answers

Short notes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views3 pages

Short Note Answers

Short notes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

**Short Note Answers:**

1. **Math functions:** The `sqrt()` function from the math library


calculates the square root of a number. It's commonly used in
mathematical calculations.

2. **String handling functions:** `scanf()` is used for accepting


user input in C. It reads formatted input from the standard input
stream.

3. **Scope of Variables:** Variable scope refers to the visibility


and accessibility of variables within a program. Local variables are
declared within a specific block or function and can only be
accessed within that block or function.

4. **Parameter Passing - Call by Value:** In call by value, the


value of the actual parameter is copied to the formal parameter of
the function. Changes made to the formal parameter do not affect
the actual parameter.

5. **Parameter Passing - Call by Reference:** In call by reference,


the address of the actual parameter is passed to the formal
parameter. Changes made to the formal parameter affect the
actual parameter.

6. **Recursive Functions:** Recursion is a technique in which a


function calls itself. It's used to solve problems that can be broken
down into smaller, similar subproblems.

**Example Code:**

```c
#include <stdio.h>
#include <math.h>

// Function to calculate the area of a circle


float calculateArea(float radius) {
return M_PI * radius * radius;
}

// Function to modify the radius


void modifyRadius(float *radius) {
*radius += 1; // Increment radius by 1
}

// Recursive function to calculate factorial


int factorial(int n) {
if (n == 0 || n == 1) {
return 1;
} else {
return n * factorial(n - 1);
}
}

int main() {
float radius;
printf("Enter the radius of the circle: ");
scanf("%f", &radius);

// Calculate radius using sqrt() function


float circleRadius = sqrt(radius);

// Calculate area using user-defined function


float area = calculateArea(circleRadius);
printf("Area of the circle: %.2f\n", area);

// Pass radius using call by value


calculateArea(radius);

// Pass radius using call by reference


modifyRadius(&radius);
printf("Modified radius: %.2f\n", radius);

// Calculate factorial using recursion


int fact = factorial(radius);
printf("Factorial of radius: %d\n", fact);
return 0;
}
```

This code covers all the topics mentioned in Unit 5.0 and
demonstrates their implementation in a program.

You might also like