Important Introduction to Programming Short Questions
Chapter: 9
Question 1:
How do you calculate the square of a number using a function in C?
Answer:
To calculate the square, define a function int square(int number) that multiplies the number by itself and returns the result.
Chapter: 9
Question 2:
What does the function raiseToPow(double x, int power) do?
Answer:
The raiseToPow function calculates the power of a number x raised to an integer power by multiplying x by itself power times.
Chapter: 9
Question 3:
How is the area of a ring calculated using functions in C?
Answer:
The area of a ring is calculated by defining a circleArea function to compute the area of a circle, and then subtracting the area of the inner circle from the outer circle.
Chapter: 9
Question 4:
How can you test if a number is even using a function in C?
Answer:
Define a function int isEven(int number) that checks if the number divided by 2 leaves no remainder, returning 1 for even and 0 for odd.
Chapter: 9
Question 5:
Question
Answer:
Answer
Chapter: 9
Question 6:
What does encapsulation in functions mean?
Answer:
Encapsulation means that the internal workings of a function are hidden from the calling program, which only interacts with the function through its interface.
Chapter: 9
Question 7:
How does function reuse improve code efficiency?
Answer:
Function reuse allows the same code to be used multiple times in different parts of a program, reducing redundancy and making the program more efficient and maintainable.
Chapter: 9
Question 8:
What is 'divide and conquer' in top-down design?
Answer:
'Divide and conquer' is a principle where a large task is broken down into smaller, manageable tasks that are easier to solve independently.
Chapter: 9
Question 9:
What is the output of result = square(5)?
Answer:
The output is 25, as the square function calculates the square of 5.
Chapter: 9
Question 10:
How can you call a function within an assignment statement?
Answer:
You can call a function directly in an assignment, like result = square(number + 10);, where the function's return value is assigned to a variable.