Title Header

 SOCIAL TECHNO

Pengertian Algoritma menurut bahasa komputer

- Pengertian Variable dalam bahasa komputer

Variabel adalah suatu nama yang menyatakan tempat dalam memori komputer untuk
Menyimpan suatu nilai dan nilainya dapat dirubah sewaktu-waktu ketika program 
sedang dieksekusi.


- Aturan - aturan dalam penulisan variable

1. Terdiri dari gabungan huruf dan angka dengan karakter pertama harus berupa huruf
2. Tidak boleh mengandung spaci
3. Tidak boleh mengandung simbol-simbol khusus kecuali underscore
4. Panjang bebas, tetapi 31 karakter pertama yang dipakai





Contoh :

DEKLARASI KETERANGAN :
int n;          |Variable n bertipe integer (bilangan bulat)
char x         |Variable x bertipe char (karakter)
long int jumlah_siswa; |Variable jumlah_siswa bertipe long                                                                       int(bil bulat panjang 2 Milyar)
Double panjang; |Variable panjang bertipe double (bil                                                                       real presisi untuk ukuran)



Contoh program

#include <iostream.h>
using namespace std;
main ()
{
       int x;
       float y;
       x=1;
       y=8;
       cout <<"x= "<<x;
       cout <<"\n";
       cout <<"y= "<<y;
       cout <<"\n";
       system ("pause");
       return 0;
       
       }


- Menampilkan sebuah variable di dev c++

1. Angka

#include <iostream.h>
#include <stdio.h>
#include <conio.h>
using namespace std;
main ()
{
       int A, B, C;
       A=12;
       B=3;
       C=A*B;
       cout <<"Nilai C = "<<C;
       cout <<endl;
       system ("Pause");
       return 0;
        
       }


2. String

#include <iostream.h>
#include <stdio.h>
#include <conio.h>
using namespace std;
main ()
{
       char X[15] = "SMK AL BAHRI";
       
       cout<<"TAMPILKAN KATA = "<<X;
       cout <<endl;
       system ("Pause");
       return 0;
        
       }


3. String Lenght

#include <iostream.h>
#include <stdio.h>
#include <conio.h>
using namespace std;
main ()
{
       char X[15] = "SMK AL BAHRI";
       int S ;
       
       cout<<"TAMPILKAN KATA = "<<X;
       cout <<endl;
       
       S=strlen (X);
       cout << S<<endl;
       
       system ("Pause");
       return 0;
        
       } 


4. Angka dan Huruf

#include <iostream.h>
#include <stdio.h>
#include <conio.h>
using namespace std;
main ()
{
       char X[50] = "SMK AL BAHRI BANTAR GEBANG BEKASI";
       int S ;
       S= 1223344;
       cout <<"TAMPILKAN KATA = "<<X;
       cout <<endl;
       
       cout <<"TAMPILKAN ANGKA= "<<S;
       cout <<endl;
       
       system ("Pause");
       return 0;
        
       } 


- Input data dengan keyboard 

1. Cin >> Variable
   digunakan untuk standrad input

#include <iostream.h>
#include <stdio.h>
#include <conio.h>
using namespace std;
main ()
{
     int y ;
     cin >> y;
     
     system ("pause");
     return 0;
     
     }

2. cint char
   digunakan untuk input data berupa karakter

#include <iostream.h>
#include <stdio.h>
#include <conio.h>
using namespace std;
main ()
{    
     char x;
     cin >> x;
     cout << x;
     cout <<endl;
     
     system ("pause");
     return 0;
     
     }

3.cin >>getch()
   digunakan untuk input langsung tampil di monitor dengan enter

#include <iostream.h>
#include <stdio.h>
#include <conio.h>
using namespace std;
main ()
{    
     char x ;
     x=getch();
     
     cout << x;
     cout <<endl;
     
     system ("pause");
     return 0;
     
     }


4. cin >>getche()
   digunakan untuk input langsung tampil di monitor tanpa enter

#include <iostream.h>
#include <stdio.h>
#include <conio.h>
using namespace std;
main ()
{    
     char x ;
     x=getche();
     
     cout << x;
     cout <<endl;
     
     system ("pause");
     return 0;
     
     }

5. cin string >> variabel

#include <iostream.h>
#include <stdio.h>
#include <conio.h>
using namespace std;
main ()
{    
     char x [7] ="smk AB";
     
     cout << x;
    
     cout <<endl;
     
     
     
     system ("pause");
     return 0;
     
     }

6. cin getline
   cin.hetline(variabel, sizeof(variabel));

#include <iostream.h>
#include <stdio.h>
#include <conio.h>
using namespace std;
main ()
{    
     char x [8];
     cin.getline (x,8);
     
     cout << x;
    
     cout <<endl;
     
     
     
     system ("pause");
     return 0;
     
     }

7. cin interger
   cin >> variabel

#include <iostream.h>
#include <stdio.h>
#include <conio.h>
using namespace std;
main ()
{    
    
    
    
    float  x ;
    x ;
    cin >>x ;
    cout <<x;
    
     cout <<endl;
     
     
     
     system ("pause");
     return 0;
     
     }

Posting Komentar

0 Komentar