/*Problem: Write a program in Java to find the sum of the series * using function name product(int,int) to return the product
* of two numbers in order to obtain each term.
* The series :-
* S=(1*2)+(2*3)+(3*4)+...+((n-1)*n)
*/
import java.util.*;
class series1
{
public static void main()
{
int n,i;
System.out.print("Enter the value of n : ");
Scanner sc=new Scanner (System.in);
n=sc.nextInt();
int S=0,pro=0;
for(i=1;i<n;i++)
{
pro=product(i,i+1);
S=S+pro;
}
System.out.println("The sum is "+S);
}
public static int product(int n1,int n2)
{
int mul;
mul=n1*n2;
return(mul);
}
}
/*Output:
Enter the value of n : 11
The sum is 440
*/
//Author : Mayank Rajoria
* of two numbers in order to obtain each term.
* The series :-
* S=(1*2)+(2*3)+(3*4)+...+((n-1)*n)
*/
import java.util.*;
class series1
{
public static void main()
{
int n,i;
System.out.print("Enter the value of n : ");
Scanner sc=new Scanner (System.in);
n=sc.nextInt();
int S=0,pro=0;
for(i=1;i<n;i++)
{
pro=product(i,i+1);
S=S+pro;
}
System.out.println("The sum is "+S);
}
public static int product(int n1,int n2)
{
int mul;
mul=n1*n2;
return(mul);
}
}
/*Output:
Enter the value of n : 11
The sum is 440
*/
//Author : Mayank Rajoria
No comments:
Post a Comment