shivamisone

ap and factorial

Jul 12th, 2023
1,059
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | Source Code | 0 0
  1. import java.util.*;
  2. public class ap{
  3.     public static void main(){
  4.         Scanner sc = new Scanner(System.in);
  5.         System.out.println("1st term");
  6.         int a = sc.nextInt();
  7.         System.out.println("difference term");
  8.         int d = sc.nextInt();
  9.         System.out.println("nth term");
  10.         int n = sc.nextInt();
  11.         prin(a,d,n);
  12.     }
  13.     static void prin(int a, int d, int n){
  14.        
  15.         System.out.println("nth term:"+ (a+((n-1)*d)));
  16.         System.out.println("sum till nth term:"+ ((n/2)*((2*a)+((n-1)*d)) ));
  17.         for(int i = 1; i<=n;i++ ){
  18.             System.out.print((a+((i-1)*d))+",");
  19.         }
  20.         System.out.println("");
  21.         for(int i = 1; i<=n;i++ ){
  22.             int k = (a+((i-1)*d));
  23.             int l = 1;
  24.             for(int j =1;j<=k;j++){
  25.                 l *=j;
  26.             }
  27.             System.out.print(l+",");
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment