Thursday, July 14, 2011

C Programming - Program Membuat Kalkulator Sederhana

#include <stdio.h>

int main()
{
    char op;
    int bil1, bil2;
    printf("Tuliskan bilangan, operator, bilangan :");
    scanf("%d %c %d", &bil1, &op, &bil2);

    switch(op)
    {
        case '+': printf("= %d", bil1 + bil2); break;
        case '-': printf("= %d", bil1 - bil2); break;
        case '*': printf("= %d", bil1 * bil2); break;
        case '/': printf("= %d", bil1 / bil2); break;
        default : printf("operator tidak dikenal!");
    }
    printf("\n\n");

    return 0;
}

No comments:

Post a Comment

LinkWithin

Related Posts Plugin for WordPress, Blogger...