Algoritma 6

TGL 12 Novermber 2015

Input>Proses>Output

>Selection

>Repetition

>Storage>file>sql>nosql

 

Input:Proses yang dimasukan user kedalam komputer

Proses: Tahap pemrosesan hasil Inputan user ke dalam komputer

Output:Hasil dari proses

Contoh coding

segitiga tanpa isi:

#include<stdio.h>

int main()

{

int n,a,b;

scanf(“%d”, &n); fflush(stdin);

for(a=1;a<=n;a++){

for(b=1;b<=a;b++){

if(b==1||a==b||a==n){

printf(“*”);

}

else{

printf(” “);

}

}

printf(“\n”);

}

getchar();

return 0;

}

Coding untuk bilangan prima

#include<stdio.h>
int main()
{

int a,b,i,c=0;

scanf(“%d”,&i);
fflush(stdin);
for(a=2;a<i+1;a++){
for(b=1;b<=a;b++)
{if(a%b==0){c++;}}

if (c==2)
{printf(“%d “,a);}c=0;}
getchar();
return 0;
}

Segitiga pascal

#include<stdio.h>
int main(){

int input;
int kolom,baris,segitiga[100][100];
scanf(“%d”,&input);
fflush(stdin);
for (baris=0;baris<input;baris++)
{
for (kolom=0;kolom<=baris;kolom++)
{
if(kolom==0 || kolom==baris)
{
segitiga[baris][kolom]=1;
}
else if(baris>1 && kolom<baris)
{
segitiga[baris][kolom]=segitiga[baris-1][kolom]+segitiga[baris-1][kolom-1];
}
printf(“%d “,segitiga[baris][kolom]);
}

printf(“\n”);
}

return 0;
}

 

Algoritma 5

Pointers & Array (29 Oktober 2015)

Defenition:Pointer is a variable that states the adress of another variable.

2 operators mostly used in pointer:*(content of) and & (adress of)

Example:int i,*ptr;

ptr=&i;

(To assign a new value pointed by the pointer:*ptr=5;/* means i=5*/)

*=konten variabel lain

tanpa *=menyimpan nilai variabel itu tapi harus menggunakan variabel lain

Pointer to pointer:A variable that saver another adress of a pointer.

Array definition

Data saved i a certain structure to be accesed as a group or individually.Some variable saved using the same name distinguish by their index.

Characteristic:

-Homogenous(All elements have similar data type)

-Random Access(Each element can be reached individualy,does not have to be sequential)

Array Initialization

Array can be initialized explicitly without dimensional value declaration.

Accsesing Array

-Two analougous ways of accesing an element 1=2;

*(A+2) or A[2]

-A is equivalent with &A[0] or a constant pointer to the first element of particular array.

Pointer Constant & Pointer Variable

-Pointer Variable:a pointer that can be assigned with new value at run-time

-Pointer Constant:a pointer that cannot be assigned with new value at run-time

One dimensional array

-C compiler does not limit number of dimensional which can be created.Our PC memory does.

Two dimension array

Inialization:using rmo(row major order)

Array of pointer:array filled with pointer/s

Array of character:Array filled with character/s

String:An array of character that ended with null character(’10’ or m ASCII=0).