Assalamualaikum.wr.wb
TUGAS OOP FIBONANCI
Fibonanci adalah program yang menjumlahkan di deret belakang tersebut
CONTOH :
1. Inputkan jumlah nilai hibonanci : 4
program akan menjalankan
1 2 3 5
contoh program hibonanci C#
MAIN PROGRAM
/*
* Created by SharpDevelop.
* User: Firman
* Date: 28/10/2014
* Time: 12:10
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
namespace oop3
{
class Program
{
public static void Main(string[] args)
{
hibo a = new hibo();
a.azura();
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
}
METHOD
/*
* Created by SharpDevelop.
* User: Firman
* Date: 28/10/2014
* Time: 12:11
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
namespace oop3
{
public class hibo
{
public void azura()
{
int x = 1, y = 1, z = 1;
Console.Write("Masukan jumlah bilangan fibonacci = ");
int jumlah = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < jumlah; i++)
{
Console.Write(z + " ");
z = x + y;
x = y;
y = z;
}
Console.Read();
}
}
}
contoh program hibonanci C++
#include <iostream>
# include <stdio.h>
# include <conio.h>
# include <windows.h>
using namespace std;
class hibonanci
{
public :
int x=1;
int y=1;
int z=1;
int pilih=0;
void tampilkan()
{
printf(" =======HIBONANCI by vebri============ \n");
printf(" Masukan jumlah bilangan hibonanci : ");
scanf ("%d", &pilih);
for (int c=1; c<=pilih; c++)
{
printf(" %d \n", z);
z = x + y;
x = y;
y = z;
}
}
};
int main()
{
hibonanci k;
k.tampilkan();
getch();
return 0;
}
contoh program hibonanci Java
Main program
package javaapplication6;
public class JavaApplication6 {
public static void main(String[] args)
{
hibonanci k = new hibonanci();
k.tampilkan();
}
}
Method
package javaapplication6;
import java.util.Scanner;
public class hibonanci
{
public int x=1;
public int y=1;
public int z=1;
public int pilih=0;
Scanner Scanner;
Scanner scn = new Scanner (System.in);
public void tampilkan()
{
System.out.print("Masukan jumlah bilangan hibonanci : ");
pilih=scn.nextInt();
for (int a=1; a<=pilih; a++)
{
System.out.print(" " + z);
z = x + y;
x = y;
y = z;
}
}
}
Wassalamualaikum.wr.wb

Tidak ada komentar:
Posting Komentar