if
(expression)
{
statements;
}
ឧទាហរណ៍
#include<stdio.h> void main () { int number; printf ("Input Number="); scanf("%d",& number ); if( number<=0) printf("%d NumberIs Negative",number); if( number>0) printf("%d NumberIs Positive ",number); }
if
(expression){
statements;
}
else
{
statements;
}
ឧទាហរណ៍
#include<stdio.h> void main () { int number; printf ("Input Number="); scanf("%d",& number ); if( number<=0) printf("%d NumberIs Negative",number); else printf("%d NumberIs Positive ",number); }
switch
(variable){
case
Constant1:
Statements;
break
;
case
Constant2:
Statements;
break
;
case
Constant(N):
Statements;
break
;
Default:
Statements;
break
;
}
#include<conio.h> #include<stdio.h> void main() { char khmer; float a,b,result; clrscr(); printf("Enter a:");scanf("%f",&a); printf("Enter b:");scanf("%f",&b); printf("Choose option[+,-,*,/]:"); fflush(stdin); scanf("%c",&khmer); switch(khmer){ case '+':result=a+b;printf ("%0.2f\n",result); break; case '-':result=a-b;printf ("%0.2f\n",result); break; case '*':result=a*b;printf ("%0.2f\n",result); break; case '/':result=a/b;printf ("%0.2f\n",result); break; } getch(); }
Expression1? Expression2: Expresion3;
#include<stdio.h> #include<conio.h> void main() { int max = 0; int a = 5; int b = 10; max = a>b?a:b; printf("Max = %d",max); getch(); }
No comments:
Post a Comment