Posts

Showing posts from December, 2018

struct

apa itu struct? Struct adalah tipe data yang ditentukan pengguna dalam C / C ++. Struktur menciptakan tipe data yang dapat digunakan untuk mengelompokkan berbagai jenis yang mungkin berbeda menjadi satu jenis. bagaimana cara memanggil struct? #include<stdio.h>   struct Point {    int x, y; };   int main() {    struct Point p1 = {0, 1};      // mengakses anggota dari p1    p1.x = 20;    printf ("x = %d, y = %d", p1.x, p1.y);      return 0; } dan dari input ini akan muncul output: x = 20, y = 1 itulah cara untuk memanggil struct di dalam C language/bahasa C

file processing

Di C, Anda dapat melakukan empat operasi besar pada file, baik teks atau biner: Membuat file baru Membuka file yang ada Menutup file Membaca dari dan menulis informasi ke file untuk melakannya kita memerlukan beberapa command khusus (dalam bahasa Inggris): File Mode Meaning of Mode During Inexistence of file r Open for reading. If the file does not exist, fopen() returns NULL. rb Open for reading in binary mode. If the file does not exist, fopen() returns NULL. w Open for writing. If the file exists, its contents are overwritten. If the file does not exist, it will be created. wb Open for writing in binary mode. If the file exists, its contents are overwritten. If the file does not exist, it will be created. a Open for append. i.e, Data is added to end of file. If the file does not exists, it will be created. ab Open for append in binary mode. i.e, Data is added to end of file. If the file does not exists, it will be created. r+ Open for both reading and wr...

array and pointer

array:Array adalah kumpulan jumlah nilai tetap dari satu jenis. Sebagai contoh: jika Anda ingin menyimpan 100 bilangan bulat secara berurutan, Anda dapat membuat larik untuknya.Contoh Kodingannya: #include <stdio.h> int main() {      int marks[10]={45,35,38,31,49}, i, n={5}, sum = 0, average;      printf("Enter n:%d \n",n);      for(i=0; i<n; ++i)      {           printf("Enter number%d:%d\n",i+1,marks[i]);           sum += marks[i];      }      average = sum/n;      printf("Average = %d", average);      return 0; } maka outputnya adalah: Enter n: 5 Enter number1:45 Enter number2:35 Enter number3:38 Enter number4:31 Enter number5:49 Average = 39 Pointer: Pointer digunakan dalam program C untuk mengakses memori dan memanipulasi alamat. Sebelum Anda masuk ke dalam konsep pointer, mari...

Function

Function data : dapat langsung mengeluarkan hasilnya, harus menggunakan command return karena function data merupakan function pengulangan, ada tipe data yang mengawali fungsi ini, dan tidak memiliki command void sama sekali. #include<stdio.h> int angka_terakhir(int x[]){             int urutan=x[0];             for(int i=1;i<5;i++){                                     urutan=x[i];             }                         return urutan; } int main(){           ...

Sort and searching

We Can use 3 simple Sort: Selection Sort Bubble Sort Insertion Sort and 2 advanced Sort: Quick Sort Merge Sort 1. Selection Sort The selection sort algorithm sorts an array by repeatedly finding the minimum element (considering ascending order) from unsorted part and putting it at the beginning. The algorithm maintains two subarrays in a given array. 1) The subarray which is already sorted. 2) Remaining subarray which is unsorted. In every iteration of selection sort, the minimum element (considering ascending order) from the unsorted subarray is picked and moved to the sorted subarray. 2. Bubble Sort Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in wrong order . 3. Insertion Sort Insertion sort is a simple sorting algorithm that works the way we sort playing cards in our hands. Algorithm // Sort an arr[] of size n insertionSort(arr, n) Loop from i = 1 to n-1. ……a) Pick element arr[i] an...