Suppose there is a given number we should test if it is product of four consecutive numbers?
So if y is our given number we should test if y=x(x+1)(x+2)(x+3)
for any arbitrary x?
How to design an algorithm for this problem?
I have done it like this:
import java.util.*;
public class _product
{
public static int product(int i)
{
return (i*(i+1)*(i+2)*(i+3));
}
public static void main(String[] args)
{
Scanner scnr=new Scanner(System.in);
int x=scnr.nextInt();
for (int i=0;i<x/2;i++)
{
if (product(i)==x)
{
System.out.println("number is product of 4 consecutive numbers");
break;
}
}
}
}