Showing posts with label bahasa pemrograman. Show all posts
Showing posts with label bahasa pemrograman. Show all posts

Monday, December 29, 2008

Tugas 6


/* Bsr. 1.1: bsr01_ISNUR.c
    Using if statements, relational
    operators, and equality operators */
#include <stdio.h>


int main()
{
    float A, B, C, besar;

    printf( "A =" );
    scanf( "%f", &A );
    printf( "B =" );
    scanf( "%f", &B );
    printf( "C =" );
    scanf( "%f", &C );

    if ( A > B )
        besar = A;
        else
        besar = B;

    if ( C > besar )
        besar = C;
        printf( "Terbesar = %f", besar );

    return 0;
}
A = 5
B = 15
C = 8
Terbesar = 15

Sunday, December 28, 2008

Tugas 3


/* Lat. 0.3: lat03.c
    Hitungan Pencacahan */
#include <stdio.h>


int main()

{
    int C = 0, N = 14;

    while ( C <= N )
    {
        printf("%d", C);
        C = C + 2;
    }
    printf( "Hitungan Terakhir = %d", C - 2 );

    return 0;
}
0 2 4 6 8 10 14
Hitungan Terakhir = 14

Tugas 5


/* ling 1.1: ling01_ISNUR.c
    area and round program */
#include <stdio.h>


int main()
{
    float r, luas, keliling;

    printf( "jari-jari = " );
    scanf( "%f", &r );
    luas = r * r * 3.14;
    printf( "luas = %f\n", luas );
    keliling = 2 * r * 3.14;
    printf( "keliling = %f\n", keliling );

    return 0;
}
jari-jari = 100
luas      = 31400
keliling  = 628

Tugas 4


/* Lat. 0.4: lat04.c
    Histogram printing program */
#include <stdio.h>

#define SIZE 10


int main()
{
    int n[ SIZE ] = { 19, 3, 15, 7, 11, 9, 13, 5, 17, 1 };
    int i, j;
        printf( "%s%13s%17s\n", "Element", "Value", "Histogram" );

    for ( i = 0; i <= SIZE-1; i++ )
    {
        printf( "%7d%13d ", i, n[ i ]);
      for ( j = 1; j <=  n[i]; j++ )
        printf( "%c", '*' );
      printf( "\n");
    }
return 0;
}



Hasil
19*******************
3***
15***************
7*******
11***********
9*********
13*************
5*****
17*****************
1*

Tugas 2


/* Lat. 0.2: lat02.c
    Hitungan Pencacahan */
#include <stdio.h>


int main()

{
    int C = 0, N = 6, D = 1;

    while ( C <= N )
    {
        printf( "%d", D );
        D = C + D;
    }
    printf( "Hitungan Terakhir = %d", D - 7 );

    return 0;
}
1 3 6 10 15 21
Hitungan Terakhir = 21

Tugas 1


/* Lat. 0.1: lat01.c
    Hitungan Pencacahan */
#include <stdio.h>


int main()

{
    int C = 2, N = 12;

    while ( C <= N )
    {
        printf("%d", C);
        C = C + 2;
    }
    printf( "Hitungan Terakhir = %d", C - 2 );

    return 0;
}
2 4 6 8 10 12
Hitungan Terakhir = 12

Saturday, December 20, 2008

A Simple C Program


/* Latihan. 2.1: lat02_01.c
A first program in C */
#include <stdio.h>

int main()

{
printf( "Welcome to C!\n" );

return 0;
}
Welcome to C!


  • Comments

  • - Text surrounded by /* and */ is ignored by computer
    - Used to describe program
  • #include <stdio.h>

  • - Preprocessor directive
    * Tells computer to load contents of a certain file
    - <stdio.h> allows standard input/output operations
  • int main()

  • - C++ programs contain one or more functions, exactly one of which must be main
    - Parenthesis used to indicate a function
    - int means that main "returns" an integer value
    - Braces ( { and } ) indicate a block
    * The bodies of all functions must be contained in braces
  • printf( "Welcome to C!\n" );

  • - Instructs computer to perform an action
    * Specifically, prints the string of characters within quotes (" ")
    - Entire line called a statement
    * All statements must end with a semicolon (;)
    - Escape character (\)
    * Indicates that printf should do something out of the ordinary
    * \n is the newline character
  • return 0;

  • - A way to exit a function
    - return 0, in this case, means that the program terminated normally
  • Right brace }

  • - Indicates end of main has been reached
  • Linker

  • - When a function is called, linker locates it in the library
    - Inserts it into object program
    - If function name is misspelled, the linker will produce an error because it will not be able to find function in the library

Wednesday, December 17, 2008

History of C

  • C
    - Evolved by Ritchie from two previous programming languages, BCPL and B;

    - Used to develop UNIX;

    - Used to write modern operating systems;

    - Hardware independent (portable);

    - By late 1970's C had evolved to "Traditional C".
  • Standardization


  • - Many slight variations of C existed, and were incompatible;

    - Committee formed to create a "unambiguous, machine-independent" definition;

    - Standard created in 1989, updated in 1999.