Tables of functions
/* Table of sines */
#include <stdio.h>
#include <math.h>
#define Pi M_PI
int main() {
int i;
i=1;
do {
printf("%d. \t %f\n",i,sin((i/90.0)*(Pi/2)));
i=i+1;
} while (i <= 90);
}
Case Construction
/* A test for case */
#include <stdio.h>
int main () {
int n;
printf("Enter n (month 1--12): ");
scanf("%d",&n);
switch(n) {
case 1 : case 2 : case 3 : printf("Winter\n");
break;
case 4 : case 5 : case 6 : printf("Spring\n");
break;
case 7 : case 8 : case 9 : printf("Summer\n");
break;
case 10 : case 11: case 12 : printf("Fall\n");
break;
}
}
#include <stdio.h>
int main () {
int i, n;
float sum;
n = 10000;
i = 1;
sum = 0.0;
while (i <= n) {
switch( i%4 ) {
case 0: case 2:
break ;
case 1:
sum = sum + 1.0/i;
break;
case 3:
sum = sum - 1.0/i;
break;
}
i = i+1;
}
printf("The sum of the series is %f.\n", sum);
}