Computer Science, asked by riasingh321p, 11 months ago

write a program in function ​

Attachments:

Answers

Answered by nain31
21
 \bold{About \: Java}

Java is a machine independent language which can work on any platform. Its an object oriented programming which stress on object rather than data.

◼Functions are the part of java programming in modules used simultaneously ay different instances to perform specific task.

 \bold{About \: Program}

◼m! and n!means the product of all numbers till m and n .

◼Then forming java expression.

 \huge{ \bold{CODING}}

import java . util . *;

class factor

{

public int fact(int n)

{

int m , S i ,j ,a=1 ,b=1 ,c=1,k;

Scanner Sc=new Scanner(System . in);

System . out . println("Enter any number");

m=Sc . nextInt();

for(i= 1;i<=m ;i++)

{

a= a*i;

}

for(j=1;j<=n;j++)

{

b=b*j;

}

for(k=1;k<=(n-m);k++)

{

c=c*k;

}

S=a/b*c;

return(S);

}

public static void main(String args[])

{

int p ,r;

Scanner Sc=new Scanner(System . in);

System . out . println("Enter any number");

r=Sc . nextInt();

factor obj=new factor(System . in);

p=obj . fact(r);

System . out . println("S"+S);

}

}

 \huge{ \bold{O U P U T}}

Enter any number

2

Enter any number

2

So,

S will be 2.

Anonymous: Supeb!!!
Anonymous: Superb**
Similar questions