Advertisements
Advertisements
प्रश्न
Write the syntax of functions.
उत्तर
The syntax of a function definition is:
Function function-name(parameters list)
{
Declaration of variable Executable statements;
}
APPEARS IN
संबंधित प्रश्न
Which of the following allow the programmer to modu/arize a program.
Write a note on user defined functions.
Does a function always return a value? Explain with an example.
Take a look at the series below:
1, 1, 2, 3, 5, 8, 13, 21, 34, 55… To form the pattern, start by writing 1 and 1. Add them together to get 2. Add the last two numbers: 1 + 2 = 3. Continue adding the previous two numbers to find the next number in the series. These numbers make up the famed Fibonacci sequence: the previous two numbers are added to get the immediate new number.
Write a program to check the divisibility of a number by 7 that is passed as a parameter to the user-defined function.
Write a program that uses a user-defined function that accepts name and gender (as M for Male, F for Female) and prefixes Mr/Ms on the basis of gender.
Write a program that has a user-defined function to accept the coefficients of a quadratic equation in variables and calculate its determinant. For example: if the coefficients are stored in the variables a, b, and c then calculate the determinant as b2-4ac. Write the appropriate condition to check determinants on positive, zero, and negative and output appropriate results.
Write a program that implements a user-defined function that accepts Principal Amount, Rate, Time, and Number of Times the interest is compounded to calculate and displays compound interest. (Hint: CI = P*(1 + r/n)nt)
Write a program that has a user-defined function to accept 2 numbers as parameters, if number 1 is less than number 2 then numbers are swapped and returned, i.e., number 2 is returned in place of number1 and number 1 is reformed in place of number 2, otherwise the same order is returned.
For the SMIS system extended in Chapter 6 let us do the following:
- 7.1 Convert all the functionality in Chapters 5 and 6 using user-defined functions.
- 7.2 Add another user-defined function to the above menu to check if the student has short attendance or not. The function should accept the total number of working days in a month and check if the student is a defaulter by calculating his or her attendance using the formula: Count of days the student was present or the total number of working days. In case the attendance calculated is less than 78%, the function should return 1 indicating short attendance otherwise the function should return 0 indicating attendance is not short.
Let’s peer review the case studies of others based on the parameters given under “DOCUMENTATION TIPS” at the end of Chapter 5 and provide feedback to them.