[java] Membuat program yang menggunakan 2 rumus matematika yang saling terhubung

METNUM

 

 

 

|Tugas METNUM: Halaman 130 no.7

Terdapat 2 rumus matematika sebagai berikut:

f(x) = 2x + 3

g(x) = f(x) + f(x-1) + f(x-2) + f(x-3) + … + f(0)

Buatlah sebuah program yang meminta sebuah bilangan x, lalu menampilkan hasil g(x).

Jawab

//irwananwar.wordpress.com
import java.util.Scanner;
public class loop7 {
	public static void main(String[] args) {
		Scanner s=new Scanner(System.in);
		System.out.printf("=========================\n");
		System.out.printf("Input sebuah bilangan : ");
		int x=s.nextInt();
		int f=2*x+3;
		for(int i=1;i<=x;i++)
			f=f+(2*(x-i)+3);
		System.out.printf(""+f);
	}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s