Jawaban Algoritma #3 FiboPlinplan

#include <iostream>
using namespace std;

int main(){
	int jmlcase, jmlderet[1000], deret[1000];
	cout << "Masukkan Jumlah Testcase : "; cin >> jmlcase;
	for(int i=1;i<=jmlcase;i++){
		cout << "Jumlah Deret ke- " << i << " : "; cin >> jmlderet[i];
	}
	jmlderet[0]=1;
	for(int j=1;j<=jmlcase;j++){
		for(int k=0;k<=jmlderet[j]-1;k++){
			if (k == 0) {
				deret[j] = deret[j] + jmlderet[k];
			}
			else{
				if ((k % 2) == 1){
					deret[j] = deret[j] - jmlderet[k];
				}else if((k % 2) == 0){
					deret[j] = deret[j] + jmlderet[k];
				}
			}

		}
	}

	for(int i=1;i<=jmlcase;i++){
		cout << deret[i] << endl;
	}

}
Iklan

9 respons untuk ‘Jawaban Algoritma #3 FiboPlinplan

  1. ini saya buat di java

    public class fiboPlinPlan{
    public void fiboo(int n){
    int c,next,first=0,second=1,sum=1;
    System.out.println(“Fibonacci “+n+” : “);
    for (c = 1 ; c < n+1 ; c++ ){
    if ( c <= 1 ){
    next = c;
    }
    else{
    next = first + (-second);
    first = second;
    second = next;
    sum=sum+next;
    }
    System.out.print(next+" ");

    }
    System.out.println("\nSum = "+sum);
    }////END METHOD
    public static void main(String[] args) {

    fiboo(5);
    }
    }///END PROGRAM

    output nya
    Fibonacci 5 :
    1 -1 2 -3 5
    Sum = 4

  2. ini saya coba buat juga mas

    #include
    int main()
    {int jmlcase=1, i, j, a, b, c, d, e, fibo[1000];

    printf(“input :\n”);
    scanf(“%i”,&jmlcase);

    while(jmlcase999)
    {scanf(“%i”,&jmlcase);
    }

    for(i=0; i<jmlcase; i++)
    {scanf("%i",&fibo[i]);
    }

    printf("\noutput\n");
    for(i=0; i<jmlcase; i++)
    {a=0; b=1; c=0; e=0;
    for(j=1; j<=fibo[i]; j++)
    {a=b+c;
    b=c;
    c=a;
    if(j%2==0)
    {d=a-a-a;
    }
    else
    {d=c;
    }
    e=e+d;
    }
    printf("%i\n",e);
    }
    }

  3. 100 % Akurat ( Bahasa Pem c# )
    //Antonius Laure
    using System;

    class Finobachi
    {
    static void Main()
    {
    int n, jb,f =0,ff=0,s=1,ss=1,t,sum=1,sam=1;

    Console.WriteLine(” Deret FinoBahci”);
    Console.WriteLine(“”);
    Console.Write(” Masukan Jumlah Testcase = “);
    n = int.Parse(Console.ReadLine());

    for (int i = 1; i <= n; i++)
    {
    if (i 1) && (i < n)) //nilai selanjutnya
    {
    t = f + (-s);
    jb = ff + ss;
    f = s;
    ss = ff;
    s = t;
    ff = jb;
    sum = sum + t; //menetukan hasil
    sam = sam + jb; // menetukan deret
    }
    else if (i == n) // penjumlahan deret terakhir
    {
    t = f + (-s);
    jb = ff + ss;
    f = s;
    ss = ff;
    s = t;
    ff = jb;

    sam = sam + jb;
    if (i % 2 == 0)
    {
    sum = sum + t + (sam );
    }
    else sum = sum + t – (sam );
    }
    Console.WriteLine("Dert {0} = {1}",sam,sum);

    } Console.WriteLine("");
    }
    }

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout /  Ubah )

Foto Google+

You are commenting using your Google+ account. Logout /  Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout /  Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout /  Ubah )

w

Connecting to %s