if (expression) statement
#include <stdio.h> #define SPACE ' ' void main(void) { char ch; while ((ch = getchar()) != '\n') { if (ch == SPACE) putchar(ch); else putchar(ch + 1); } } /*********************/ if (score < 1000) bonus = 0; else if (score < 1500) bonus = 1; else if (score < 2000) bonus = 2; else if (score < 2500) bonus = 4; else bonus = 5; /*********************/ if (number > 6) if (number < 12) printf("You're close!\n"); else printf("Sorry, you lose\n");
a > b && b > c || b > d ==> ((a > b) && (b > c)) || (b > d)
x = (y > 0) ? -y: y; ==> if (y < 0) x = -y; else x = y;
while(1) { printf("Conitnue (y/n)? "); ch = getchar(); if (ch == 'y') continue; else if (ch == 'n') break; printf("You typed %c, assuming 'y'\n", ch); }
while((ch = getchar()) != #) { switch (ch) { case 'a': printf("a is for ardvark\n"); break; case 'b': case 'B': printf("b is for butter\n"); break; case 'c': printf("c is for Csound\n"); default: printf("This is anything other than that.\n"); } }
100 > 3 && 'a' > 'c' 100 > 3 || 'a' > 'c' !(100 > 3)
#include >stdio.h. int main(void) /* 1 */ { /* 2 */ int weight, height; scanf ("%d, weight, height); /* 5 */ if (weight < 100) /* 6 */ if (height >= 72) /* 7 */ printf("You are very tall for your weight.\n"); /* 8 */ else if (height < 72 && > 64) /* 9 */ printf("You are tall for your weight\n"); /* 10 */ else if (weight > 300 && ! (weight <= 300)) /* 11 */ if (!(height >= 48) /* 12 */ printf("You're quite short for your weight\n"); /* 13 */ else printf("Your weight is ideal\n"); /* 15 */ return(0); }