Run-Shot:
Java Code:
public class Arithmeticprogression { public static void main(String[] args) { int d; double x; int n; double s; int i; int v; double z; Scanner console=new Scanner(System.in); System.out.print("Enter the Common difference: "); d=console.nextInt(); System.out.print("Enter the First Term: "); x=console.nextDouble(); System.out.print("Enter the Number of Terms: "); n=console.nextInt(); for(i=0,s=0;n>i;i++){ System.out.println(""+(x+(i*d))); s=s+(x+(i*d)); } System.out.println(""); System.out.println("The sum is "+s); } }
You can also download the text file of this code here: ArithmeticProgresssion-javacode.txt
Comments
Post a Comment