Selasa, 17 Mei 2011

Program menjumlah dan mengurang 2 bilangan integer

An array is a structured data type contained in the memory consisting of a number of elements (a) which has the same data type, variable type, number of components common tetap.Bentuk declaring:

nama_array [jumlah_eleman];

This program is a program for addition and subtraction of two integer values, where there are two input data (i, j) consisting of some value, then processed with a formula for (i = 0; i <m; i + +) {
     court <<"number to [" <<i +1 <<"] =";
then amount = bil1 + bil2 for the addition and to a reduction of less = bil1-bil2.

Algoritm:
Algorithms look for addition and subtraction of two integer values.
{search algorithms, enter inputan numbers, search process, algorithm output}
Deklarasi:
                N,bil1,bil2,jum,kur [100]: integer
Deskripsi:
                for (i=0;i<m;i++){
                    cout<<"angka ke [ "<<i+1<<"] = "
 jumlah[i]= bil1[i] + bil2[i]
jumlah[i]=bil[i]-bil[i]
                endfor;
Output:
                result of addition and subtraction


#include <cstdlib>
#include <iostream>
using namespace std;

void masukkan(int[100], int);
void penjumlahan(const int[100], const int[100], int, int[100]);
void pengurangan(const int[100], const int[100], int, int[100]);
void cetak_bigInteger(const int A[100], int);
int main(int argc, char *argv[])
{
    int n;
    int bil1[100], bil2[100];
    int jumlah[100];
    int kurang[100];

    cout<<"Masukkan bilangan : \n";
    cin>>n;
    cout<<"Bilangan pertama : \n";
    masukkan(bil1, n);
    cetak_bigInteger (bil1, n);
    cout<< "\nBilangan kedua : \n" <<endl;
    masukkan(bil2, n);
    cetak_bigInteger (bil2, n);
    penjumlahan (bil1, bil2, n, jumlah);
    cout<<" \n Hasil penjumlahan : \n";
    cetak_bigInteger (jumlah, n);
    pengurangan (bil1, bil2, n, kurang);
    cout<<" \nHasil pengurangan : \n";
    cetak_bigInteger (kurang, n);
    system("PAUSE");
    return EXIT_SUCCESS;
}
void masukkan(int B[100], int m){
     int i;
     for (i=0;i<m;i++){
     cout<<"angka ke [ "<<i+1<<"] = ";
     cin>>B[i];
             }
     }
void penjumlahan(const int bil1[100], const int bil2[100], int m, int jumlah[100]){
     int i;
     for(i=0; i<m; i++)
      jumlah[i]= bil1[i] + bil2[i];
      }
void pengurangan(const int bil1[100], const int bil2[100], int m, int kurang[100]){
     int i;
     for(i=0; i<m; i++)
      kurang[i]= bil1[i] - bil2[i];
      }
void cetak_bigInteger(const int A[100], int m){
     int i;
     for(i=0; i<m; i++){
     cout<<"       " << A[i];
     }
     }

Tidak ada komentar:

Posting Komentar