User Defined Methods or Functions Grade 10 B
User Defined Methods or Functions Grade 10 B
Grade 10 B
Define a function
1. Pass by value.
2. Pass by reference.
Differentiate between pure and impure functions.
if(x%n == 0)
System. out.println(x);
}
if 12 is passed to n.
void test3(char c)
{
System.out.println( (int) c);
}
if 'm' is passed to c.
Write a program to input a number. Use a function int
Armstrong(int n) to accept the number. The function
returns 1, if the number is Armstrong, otherwise zero(0).
Sample Input: 153
Sample Output: 153 ⇒ 13 + 53 + 33 = 153
It is an Armstrong Number.
Prototype:
function header is called as
Create a prototype of function sum which returns a float value and takes two
integer augments .
Function access specifier return type function name
parameter list
public float sum(int a , int b)
{
}
Create a function prototype of Student
which return string value and takes one
float , one double and one int arguments.
public String Student (float a, double b, int c)
{
}
Write a function fact(int n) to find the factorial of a number n. Include a main
class to find the value of S where:
S = n! / (m!(n - m)!)
where, n! = 1 x 2 x 3 x .......... x n