Algorithm and Programming
Nama : Andhika Naafi Ramadhan
NIM : 2201791093
Email : andhika.ramadhan@binus.ac.id
Tugas Algorithm and Programming
======================================================================
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:
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
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;
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;
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]
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:
- #include <stdio.h>
- int main()
- {
- int n, first = 0, second = 1, next, c;
- printf("Enter the number of terms\n");
- scanf("%d", &n);
- printf("First %d terms of Fibonacci series are:\n", n);
- for (c = 0; c < n; c++)
- {
- if (c <= 1)
- next = c;
- else
- {
- next = first + second;
- first = second;
- second = next;
- }
- printf("%d\n", next);
- }
- return 0;
- }
==============================================================================================
1. Sorting AlgorithmsSorting 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
Post a Comment