Algorithm and Programming

Nama : Andhika Naafi Ramadhan
NIM : 2201791093
Email : andhika.ramadhan@binus.ac.id



Tugas Algorithm and Programming

1.Repetition
   Repetition is one or more instruction that can be repeated for a certain amount of time.
   Operators : -for
                      -while
                      -do-while
   Repetition: - For
   example : for(exp1,exp2,exp3)statement;
   exp1 : initialization
   exp2 : conditional
   exp3 : increment or decrement
   all of them are optional.

   Repetition: -While
   example : while(exp)statements;
   or:
      while(exp)
   {
      statement1;
      statement2;
   }

   Repetition: Do-while
   example : do{statements;}
                    while(exp);
   

   In all of the exp in repetition, if the statements is false the operator will not run the code.

   2. Break
   Break is an operator that is used to end a repetition.
   for example:

   int algo;
   for(int algo=0;algo<semester2;algo++){
      if(algo>9000)break;
   }
       

3. Pointer
   Pointer is a variable that saves a memory address.
   For example:  
   <type> *ptr_name :
   int i,*ptr;
   *ptr=&i;   
   Pointer to pointer example:
   int i,*ptr,**ptr_ptr;
   ptr=&i;
   ptr_ptr=&ptr;

4. Array
   Array is a data structure that can store many value, it can store string and integers.
   Example :
   syntax = type array_value[value_dim]
   1D Array example = int angka[100] or char kata[190]
   2D Array example = int matriks1[10][10]
   


======================================================================
1. Function

   Function in programming is a group of statements that together perform a task. Every C program has at least one function, for example: main(). function can divide your code into several parts.

2. Recursive
   Recursive is similar to function but it can call the recursive itself inside its recursive, for example if your want to create a fibonacci recursive:

  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5.   int n, first = 0, second = 1, next, c;
  6.  
  7.   printf("Enter the number of terms\n");
  8.   scanf("%d", &n);
  9.  
  10.   printf("First %d terms of Fibonacci series are:\n", n);
  11.  
  12.   for (= 0; c < n; c++)
  13.   {
  14.     if (<= 1)
  15.       next = c;
  16.     else
  17.     {
  18.       next = first + second;
  19.       first = second;
  20.       second = next;
  21.     }
  22.     printf("%d\n", next);
  23.   }
  24.  
  25.   return 0;
  26. }
==============================================================================================
1. Sorting Algorithms
   Sorting is used to rearrange a data into a certain arrangement, for example if you want to sort a data into an ascending data:
array{5,4,6,2,1,3} ------ after sorting ----->  {1,2,3,4,5,6}
there are many types of sorting such as: bubble sort, merge sort

Comments