{
pernyataan
}
hanya jika kondisi benar sebuah pernyataan akan ditampilkan , jika kondis salah akan ditampilakn blank code
misal
int x=9;
if(x= =9)
{
printf("%i",x);
}
< less than
<= less than or equal to
> greater than
>= greater than or equal to
== equal to
!= not equal to
<= less than or equal to
> greater than
>= greater than or equal to
== equal to
!= not equal to
====================================
if else statement
kondisi benar atau salah tetap akan ditampilkan
misal
int x=90;
if(x>120)
{
printf("helo programmer");
}
else
{
printf("helo helo"); //result helo helo
}
}
int main() {
int y;
int x = 2;
y = (x >= 5) ? 5 : x; //cara baca
apakah x >5 atau x=5 ???? jika benar y=5
jika salah y=x
printf("%d", y); //result 2
return 0;
}
y = (x >= 5)? 5 : x
is x greater than or equal to 5?
yes? y = 5;
no? y = x;
/* This is equivalent to:
if (x >= 5)
y = 5;
else
y = x;
*/
if (x >= 5)
y = 5;
else
y = x;
*/
===========================
#include <stdio.h>
int main() {
int y, x = 3;
y = (x > 5) ? 5 : (x = 3) ? 38 : 4;
printf("%i",y);
return 0;
}
Tidak ada komentar:
Posting Komentar