Wednesday, October 17, 2018

Rangkuman 17/10

Pointer
1. Syntax:
<type> *ptr_name;
2. Example:
int i,*ptr;
ptr = 41;

Pointer to Pointer
1. Syntax
type **ptr_ptr
2. Example
int i ,*ptr, **ptr_ptr;
ptr-&i;
ptr_ptr = &ptr

Array
1.Syntax:
typearray_value[valuedim];
2 Example:
Int A[10]

Example of Array Initialization
Int B[5]={1,2,-4,8};

Example Pointer Constant and Pointer variable
Int x=10, y=20;
int *ptr;
ptr = &x;
ptr = &y;

Accesing Array
int array[10];
int *ptr_arr;
ptr_arr = arr;;

3 type of array
1. One dimensional array
2. Two dimensional array
3. Three dimensional array

string manipulation
1. strlen()
2. strcpy(s1,s2)
3. strncpy(s1.s2)
4. strcat(s1,s2)
5. strcmp9s1,s2)
etc

Wednesday, October 10, 2018

Tugas rangkuman

              Repetisi For

for(exp1; exp2; exp3) statement;

atau

for(exp1; exp2; exp3)
  statement1;
  statement2;

exp1 :  initialization
exp2 :  conditional
exp3 :  increment or decrement

Contoh program untuk membuat angka 1 sampai 10

#include<stdio.h>

int main()
{
    int x;
    for( x = 1 ;  x <= 10 ;  x++ ) printf( "%d\n", x );
    return(0);
}


Repetisi While
while (exp) statements;

or:
while(exp){
  statement1;
  statement2;
}


Contoh Koding repetisi while

#include<stdio.h>

int main() {
   int x;
   for( x = 1x <= 10x++ )
         printf( "%d\n", x );
}

             Repetisi Do-While

do{
    < statements >;
} while(exp); 

             Contoh Koding repetisi do-while
#include <stdio.h>
int main()
{
         int width, height, area; char repeat;
         printf(”Continue ? (Y/N) :”);
         scanf(”%c”,&repeat);
         while((toupper(repeat)) == ’Y’) {
  printf(” Width : ”);
  scanf(”%d”,&width);
  printf(” Height : ”);
  scanf(”%d”,&height);
  area = width*height;
  printf(” Area = %d\n\n”,area);
  printf(”Continue ?(Y/N):”);
  scanf(”%c”,&repeat);
         }
         return(0);
}