You are on page 1of 2

CONTOH PROGRAM

// Menguji bilangan ganjil genap

#include <stdio.h>
int main() {
int number;
printf("Enter an integer: ");
scanf("%d", &number);

// True if the remainder is 0


if (number%2 == 0) {
printf("%d is an even integer.",number);
}
else {
printf("%d is an odd integer.",number);
}

return 0;
}

// Program Menampilkan Bilangan Negeatif

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

printf("Masukkan Bilangan Bulat: ");


scanf("%d", &number);

// true if number is less than 0


if (number < 0) {
printf("Input Bilangan %d.\n", number);
}

printf("Mudahnya Bahasa C.");

return 0;
}
// Program Kalkulator Sederhana
#include <stdio.h>

int main() {
char operation;
double n1, n2;

printf("Masukkan operator (+, -, *, /): ");


scanf("%c", &operation);
printf("Enter 2 Angka: ");
scanf("%lf %lf",&n1, &n2);

switch(operation)
{
case '+':
printf("%.1lf + %.1lf = %.1lf",n1, n2, n1+n2);
break;

case '-':
printf("%.1lf - %.1lf = %.1lf",n1, n2, n1-n2);
break;

case '*':
printf("%.1lf * %.1lf = %.1lf",n1, n2, n1*n2);
break;

case '/':
printf("%.1lf / %.1lf = %.1lf",n1, n2, n1/n2);
break;

// operator doesn't match any case constant +, -, *, /


default:
printf("Error! operator salah");
}

return 0;
}

You might also like