|
|||
Department of Engineering | |
University of Cambridge > Engineering Department > computing help |
#include <stdio.h> #include <stdlib.h> main() { int i; for (i=0; i<10; i=i+1); printf("i is %d\n",i); }
#include <stdio.h> #include <stdlib.h> main() { int numbers[10]; int i; for (i=1;i<=10;i++) numbers[i]=i; for (i=1;i<=10;i++) printf("numbers[%d]=%d\n", i, numbers[i]); }
#include <stdio.h> #include <stdlib.h> main() { int i; for (i=0; i<10; i=i+1) if (i=2) printf("i is 2\n"); else printf("i is not 2\n"); }
#include <stdio.h> #include <stdlib.h> main() { int i; for (i=0; i<10; i=i+1) if (i<2) printf("%d is less than 2\n",i); printf("and %d is not equal to, 2 either\n",i); }
#include <stdio.h> #include <stdlib.h> main() { int i; i = 0; while (i < 10); i = i + 1; printf("Finished. i = %d\n",i); }
#include <stdio.h> #include <stdlib.h> main() { int i; for (i=0; i<10; i=i+1) switch(i){ case 0: printf("i is 0\n"); case 1: printf("i is 1\n"); default: printf("i is more than 1\n"); } }
#include <stdio.h> #include <stdlib.h> main() { int i; for (i=0; i<10; i=i+1) /* check the value of i*/ switch(i){ /* is i 0? case 0: printf("i is 0\n"); break; /* is i 1? case 1: printf("i is 1\n"); break; /* now the default case */ default: printf("i is more than 1\n"); } }
#include <stdio.h> #include <stdlib.h> main() { int i; i=3; i=i+2*i++; printf("i is now %d\n",i); }
#include <stdio.h> int main() { int a,b,c; int *pointer; c = 3; pointer = &c; /* divide c by itself */ a = c/*pointer; b = c /* set b to 3 */; printf("a=%d, b=%d\n", a,b); }
#include <stdio.h> #include <stdlib.h> typedef struct { double *par; double *pos; double *vel; } ajoint; main() { ajoint *joint; joint = (ajoint *) malloc(sizeof(ajoint) + sizeof(double)); joint->pos = (double*) (joint +1); *(joint->pos) = 0; }