Computer Science, asked by divithswarup2146, 11 months ago

Write a program that asks the user for a number n and gives them the possibility to choose between computing the sum and computing the product of 1,,n. In javascript example

Answers

Answered by Anonymous
3

Explanation:

The code is supposed to ask the user whether to find the sum of numbers from 1 to x or finding the factorial of x. After taking the user's input for the ... use.

Mark as Brainliest

Answered by anshitashrivastavaa1
0

Answer:import java.util.Scanner;

public class Main {

public static void main(String[] args) {

 int i,sum=0,pro=1;

   Scanner s = new Scanner(System.in);

        int n = s.nextInt();

                int n1 = s.nextInt();

      if(n1==1)

      {

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

    {

     sum=sum+i;

    }

       System.out.println(sum);

      }

      else if(n1==2)

      {

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

    {

     pro=pro*i;

    }

       System.out.println(pro);

      }

      else

       System.out.println(-1);

}

}

Similar questions