Presentasi sedang didownload. Silahkan tunggu

Presentasi sedang didownload. Silahkan tunggu

Konsep Pemrograman Contoh Program C # include int main() { printf("Hello World From About\n"); getche (); return 0; }

Presentasi serupa


Presentasi berjudul: "Konsep Pemrograman Contoh Program C # include int main() { printf("Hello World From About\n"); getche (); return 0; }"— Transcript presentasi:

1 Konsep Pemrograman sbw@javagroup.co.id

2 Contoh Program C # include int main() { printf("Hello World From About\n"); getche (); return 0; }

3 Contoh Program C++ #include main() { /* ini program C pertama saya */ cout<<" Konsep Pemrograman"<<endl; cout<<"\nMahasiswa : Ali"<<endl; cout<<"Kelas : 413"<<endl; getch(); }

4 Operator 4 TIPIKAL PROGRAM C # include # define MAKS 100 int hitung (int x) {... return...; } int main () { int a, b;... b = hitung (a);... return 0; } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Prepocessor directive Function hitung() Function main()

5 5 TIPIKAL PROGRAM C Komentar – Memberi keterangan kepada program. – Dituliskan diantara /* dan */. – Komentar tidak boleh nested. – /*ini sebuah komentar*/ – "/* ini bukan komentar melainkan string */" – /* komentar /* seperti ini */ akan menimbulkan kesalahan */

6 #include In C, #include forms a preprocessor directive that tells the C preprocessor to look for a file and place the contents of the file in the location where the #include directive indicates. The preprocessor is a program that does some preparations for the C compiler before your code is compiled. The name of the stdio.h file stands for standard input-output header file.

7 main () This is a very special function in C. Every C program must have a main() function, and every C program can only have one main() function You can put the main() function wherever you want in your C program. However, the execution of your program always starts with the main() function.

8 One more important thing about main() is that the execution of every C program ends with main(). A program endswhen all the statements within the main() function have been executed.

9 The Newline Character (\n) In the printf() function, one thing worth mentioning at this moment is the newline character, \n. Usually suffixed at the end of a message, the newline character tells the computer to generate a carriage-return and line-feed sequence so that anything printed out after the message will start on the next new line on the screen.

10 Contoh Aplikasi C #include main() { int a = 7; char b = 'G'; clrscr(); printf("%c Merupakan Abjad Yang Ke - %d", b, a); }

11 ELEMEN BAHASA C Karakter Identifier – Keyword – Standard identifier – Programmer-defined identifier Tipe data Konstanta Variabel

12 KARAKTER JenisRincian HurufA B C sampai dengan Z a b c sampai dengan z Angka0 1 2 3 4 5 6 7 8 9 Karakter khusus! " # % & ' ( ) * +, -. / : ; ? [ \ ] ^ _ { | } ~ spasi Karakter extendTab horisontal, tab vertikal, form feed, new line

13 IDENTIFIER Identifier – Identitas, pengenal, nama segala sesuatu – Nama instruksi, nama variabel, nama tipe data, nama function Ketentuan identifier – Diawali huruf atau garis bawah (underscore) – Diikuti huruf, angka, atau garis bawah – Panjang maksimum 32 karakter (Borland C++) Bahasa C bersifat case sensitive – Huruf besar dan kecil dianggap beda – abc berbeda dengan Abc AbC ABC abC

14 IDENTIFIER Identifier yang panjang – luas_persegipanjang_berwarna_biru – luas_persegipanjang_berwarna_biru_muda Contoh identifier yang benar – luas – segi3 – bilangan_1 Contoh identifier yang salah – 3com diawali angka – persegi-panjang terdapat - – luas lingkaran dipisahkan spasi

15 KEYWORD Keyword – Identifier yang telah diberi kegunaan tertentu dan tidak boleh diubah 1 auto 9 double 17 int 25 struct 2 break 10 else 18 long 26 switch 3 case 11 enum 19 register 27 typedef 4 char 12 extend 20 return 28 union 5 const 13 float 21 short 29 unsigned 6 continue 14 for 22 signed 30 void 7 default 15 goto 23 sizeof 31 volatile 8 do 16 if 24 static 32 while

16 Operator16 STANDARD IDENTIFIER Standard Identifier – Identifier yang telah didefinisikan compiler untuk kegunaan tertentu int main () {... printf("POTONGAN HARGA SUSU\n"); // OK... } int main () {... printf("POTONGAN HARGA SUSU\n"); // OK... } int main () { float printf; // OK... printf("POTONGAN HARGA SUSU\n"); // ERROR... } int main () { float printf; // OK... printf("POTONGAN HARGA SUSU\n"); // ERROR... }

17 PROGRAMMER-DEFINED ID Programmer-Defined Identifier – Identifier yang dibuat oleh pemrogram int main () { float j_unit, harga; // OK... scanf("%f %f", &j_unit, &harga); // OK printf("POTONGAN HARGA SUSU\n");... } int main () { float j_unit, harga; // OK... scanf("%f %f", &j_unit, &harga); // OK printf("POTONGAN HARGA SUSU\n");... }

18 TIPE DATA Tipe Data – Jenis data yang diolah – Bilangan bulat, bilangan pecahan, karakter Tipe dataKeywordRentang Nilai (GCC) Character char –128 s.d. 127 Short integer short –32.768 s.d. 32.767 Integer int –2.147.483.648 s.d. 2.147.483.647 Long integer long –2.147.483.648 s.d. 2.147.483.647 Long-long integer long –9.223.372.036.854.775.808 s.d. 9.223.372.036.854.775.807 SP loating point float 1.17 x 10 –38 s.d. 3.4 x 10 38 DP floating point double 2.22 x 10 –308 s.d. 1.79 x 10 308

19 Operator 19 TIPE DATA Tipe data karakter ( char ) – 1 byte = 8 bit – 2 8 = 256 nilai  -128 … -1 0 1 2 … 127 Tipe data short integer ( short ) – 2 byte = 16 bit – 2 16 = 65536 nilai  -32768 … 32767 Tipe data integer ( int ) – 4 byte = 32 bit – 2 32 = 4.294.967.296 nilai –  –2.147.483.648 … 2.147.483.647

20 Operator 20 TIPE DATA # include int main() { printf("char = %d\n", sizeof(char)); printf("short = %d\n", sizeof(short)); printf("int = %d\n", sizeof(int)); printf("long = %d\n", sizeof(long)); printf("float = %d\n", sizeof(float)); printf("double = %d\n", sizeof(double)); printf("long long = %d\n", sizeof(long long)); printf("long double = %d\n", sizeof(long double)); return 0; } # include int main() { printf("char = %d\n", sizeof(char)); printf("short = %d\n", sizeof(short)); printf("int = %d\n", sizeof(int)); printf("long = %d\n", sizeof(long)); printf("float = %d\n", sizeof(float)); printf("double = %d\n", sizeof(double)); printf("long long = %d\n", sizeof(long long)); printf("long double = %d\n", sizeof(long double)); return 0; } char = 1 short = 2 int = 4 long = 4 float = 4 double = 8 long long = 8 long double = 12 char = 1 short = 2 int = 4 long = 4 float = 4 double = 8 long long = 8 long double = 12

21 Operator 21 TIPE DATA Qualifier unsigned pada tipe data – Tidak mengakomodasi nilai negatif – Seluruh daya tampung untuk bilangan positif – Default qualifier adalah signed KeywordRentang Nilai (GCC) unsigned char 0 s.d. 255 unsigned short 0 s.d. 65.535 unsigned int 0 s.d. 4.294.967.295 unsigned long 0 s.d. 4.294.967.295 Unsigned long long 0.. 18.446.744.073.709.551.615

22 Operator 22 TIPE DATA Single precision floating number ( float ) versus double precision floating number ( double ) # include int main() { printf(" 123456789A123456789B\n"); printf("%.20f\n", (float)22.0 / (float)7.0); printf("%.20lf\n", (double)22.0 / (double)7.0); return 0; } # include int main() { printf(" 123456789A123456789B\n"); printf("%.20f\n", (float)22.0 / (float)7.0); printf("%.20lf\n", (double)22.0 / (double)7.0); return 0; } 123456789A123456789B 3.14285707473754880000 3.14285714285714280000 123456789A123456789B 3.14285707473754880000 3.14285714285714280000

23 Operator 23 KONSTANTA Konstanta ialah nilai konstan – Integer constant Konstanta integer desimal: 125 2010 Konstanta integer oktal: 07 0642 Konstanta integer heksadesimal: 0x36 0Xab5 – Character constant: ‘a’ ‘1’ escape sequence escape sequence diawali garis miring terbalik – Floating point constant: 3.14 1.23e4 – String constant “algoritma\npemrograman”

24 Operator 24 KONSTANTA Escape sequence ESNilaiKarakterKeterangan \0 0x00NULkarakter dengan nilai ASCII = 0 \a 0x07BELbunyi speaker \b 0x08BSbackspace (mundur ke kiri) \f 0x0CFFformfeed (ganti halaman) \n 0x0ALFLinefeed atau newline (ganti baris) \r 0x0DCRcarriage return (ke awal baris) \t 0x09HTtabulator horisontal \v 0x0BVTtabulator vertikal \\ 0x5C\karakter miring kiri \’ 0x27‘karakter petik-tunggal \” 0x22“karakter petik-ganda \? 0x3F?karakter tanda tanya

25 Operator 25 KONSTANTA Integer constant: desimal, oktal, heksadesimal # include int main() { printf("123 (10) = %d\n", 123); printf("123 (8) = %d\n", 0123); printf("123 (16) = %d\n", 0x123); return 0; } # include int main() { printf("123 (10) = %d\n", 123); printf("123 (8) = %d\n", 0123); printf("123 (16) = %d\n", 0x123); return 0; } 123 (10) = 123 123 (8) = 83 123 (16) = 291 123 (10) = 123 123 (8) = 83 123 (16) = 291

26 Operator 26 VARIABEL Variabel – Tempat menampung data – Harus ditentukan tipe data yang ditampung – Harus dideklarasi atau didefinisi sebelum dipakai  data_type var1, var2,... ; unsigned int nilai_tugas; int nilai_uts, nilai_uas; char huruf; unsigned int nilai_tugas; int nilai_uts, nilai_uas; char huruf; float jumlah = 0.0; char titik = '.'; float jumlah = 0.0; char titik = '.';


Download ppt "Konsep Pemrograman Contoh Program C # include int main() { printf("Hello World From About\n"); getche (); return 0; }"

Presentasi serupa


Iklan oleh Google