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;
	}

}

8 thoughts on “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);
    }
    }

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 )

Gambar Twitter

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

Foto Facebook

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

Foto Google+

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

Connecting to %s