• Pada Algoritma pencarian banyak yang bisa kita temukan atau gunakan. Ada Merge Sort, Quick Sort, Bubble Sort, dan...
  • Pada dasarnya algoritma searching banyak kita jumpai. Apalagi hanya untuk mencari nilai minimum dan nilai maximum...
  • Kalian pasti sudah tahu apa itu Deret Fibonacci, ya benar. (Padahal gak jawab). Tetapi pada pembahasan kali ini kita akan membuar program...
  • Metoda Pencarian Biner ( Binary Search) hanya bisa diterapkan jika data array sudah terurut. Pengurutan Array bisa menggunakan jenis sorting ...
  • Salah satu contoh tipe algoritma brute force lainnya adalah linear search (pencarian berurutan), Dikatakan demikian karena algoritma ini menggunakan ...

Friday, May 13, 2011

Big Integer : Many Digit Addition with Integer Data Type (Penjumlahan Banyak Digit dengan Tipe Data Integer)

You all know that the numbers are integer data types must be limited to 10 digits only. And what if kitaa want to add a lot of digits. Suppose we have a 30-digit numbers. Surely if we create a program using only integer types aka error results. Therefore, we can use arrays. Each digit aka stored in a single array element. Example :

We take the first number 57575757, the second number 12345678
In the program number will be stored in each array element.

The first number
5
7
5
7
5
7
5
7


The second number
1
2
3
4
5
6
7
8

 

Having obtained such that every sum of digits performed live. But here happened the outcome of the sum is also stored role in every element of the array. As the above example will occur 7 + 8 = 15. Number 15 aka the last element stored in the array. So we must be smart - smart play with the computer. We use modulo to get the number 5. So that is not stored in the memory array 15. The next smaller digit we add 1. Because 10 of 15 had been added in front of him. As usual summation in primary schools.

Based on that logic could be a program that can count up the number of big integers. That is the number of type integer, but has plenty of appropriate digits we want.

Writing can be made ​​like this :
void aritmatika::penjumlahan(){
     for(int i=(digit-1);i>=0;i--){
             jumlah[i]=jumlah[i]+input1[i]+input2[i];
             if (jumlah[i] >9 && i !=0){
                               jumlah[i]=jumlah[i]%10;
                               jumlah[i-1]=jumlah[i-1]+1;
                               }
             }
     }

Easy right opponent? Next let us work. For all the code themselves can be downloaded here
Readmore

Vektor : Program C + + Vector Addition and Multiplication Vector (Program C++ Penjumlahan Vektor dan Perkalian Vektor)

SKALAR AND VEKTOR

Scalar is a quantity sufficient magnitude is expressed alone (not dependent on the way). For example: mass, time, energy and so on.
The vector is a quantity that depends on the direction. For example: speed, force, momentum, etc.

In Cartesian coordinates :
       Vector direction / unit vector is a vector of magnitude 1 and in accordance with a defined direction. For example in Cartesian coordinates: i, j, k, respectively - each state vector in the direction parallel to the x axis, y axis and the axis z.
        So that the vector a can be written :

                                a = ax  i + ay  j

          and the large vector a is :
         
                                a = sqrt( ax +  ay 2 )
Addition operation :
A + B = ?
        + Sign in the summation vector has extended meanings.
         So A + B has a mean vector A may be extended by the vector B.

Vector multiplication by scalar :
Examples of a vector multiplication by a scalar in physics: F = ma, p = mv, etc.
where m: scalar and a, v: vector.
If for example A and B are vectors and k is a scalar then,

                    B = k A

Large vector B is k times while the direction of the vector A vector B is equal to the direction of vector A when k positive and the opposite if k is negative. Example: F = QE, q is the electric charge can be charged positive or negative so that the direction of F depends on the charge sign.

Based on the case, here's created a program to compute the vector addition and multiplication by a scalar vector. To sum ​​as follows :

void vektor::penjumlahan_vektor(const vektor& a, const vektor& b){
     if (a.banyak > b.banyak) banyak = a.banyak;
     else banyak = b.banyak;
     for(int i=0;i<banyak;i++){
             elemen[i] = a.elemen[i] + b.elemen[i];
             }
     }
    
For vector multiplication with skalar be made ​​like this :

void vektor::perkalian_vektor(float k, const vektor& d){
     banyak = d.banyak;
     for(int i=0;i<banyak;i++){
             elemen[i]=k * d.elemen[i];
             }
     }

Complete program can be downloaded here
Readmore

Friday, May 6, 2011

Pretes dan Postes Praktikum ke-7 Algoritma dan Pemrograman

Download dibawah ini :




Readmore

Rekursif : Calculating the Value Program with Recursive Factorial (Program Menghitung Nilai Faktorial dengan Rekursif)

In mathematics, the factorial of n natural numbers is the result of multiplication of positive integers less than or equal to n. Factorial written as n! and is called n factorial.

For example, 5! is worth 5×4×3×2×1 = 120.

Recursive function is a function that does the loop by calling itself.
The definition is recursive, which is defined for n>= 0












C++ is recursively defined as follows











Complete the program you can downloaded here

referensi :
Readmore

Tuesday, May 3, 2011

Jeliot version : Make a Pyramid Star with Jeliot (Menbuat Piramida Bintang dengan Jeliot)


Sometimes - sometimes at the university each began learning the looping problem (loop) we will see a task to create a pyramid of stars. Therefore I will discuss the issue and help solve it.
To create a pyramid of stars we have to use nested loops. Nested iteration loops is contained in the loop. The loop is suitable for making this pyramid is using for loop. Why choose for loop? Because of this loop for sure. We will repeat how many times can be determined easily.
How does the writing program ?
Here I use the compiler Jeliot, so that the manufacturing process can be seen easily. So it can easily to be understood. First we create a loop to limit / line. After that we created also in the loop iteration space in order to print can bitang sebada middle. The second we live looping to create a star print.
Let not this footage dizziness program :
    // to determine the line
for (baris=1;baris<=tinggi;baris ++){
                 //print the space
                 for (i=1;i<=tinggi-baris;i++){
       System.out.print(" ");
       }
                 //star print
                 for (j=1;j<2*baris;j++){
       System.out.print("*");
       }
System.out.println();
}

After dbuat program and will run resulting in output like the following :

For program details can be downloaded here. Hopefully helpful friend. Do not forget to comment!
Readmore

Tutorial Algorithm and Programming ©Template Blogger Green by Dicas Blogger.

To Up