Chapter 7 too ?
Chapter 7:
Made a program to compute e to some arbitrary level of precision. Its not working correctly right now, but the c language stuff appears to be solid.
Chapter 8:
Reading about signed, unsigned, long and short ints. The book said I can look in in the standard library to find their various limits (which vary according to machine architecture). How do I do that? Is there a good way to tell how this working on different machines and compilers? Reading further, I see sizeof could be the right tool for the job here.
Read about the difference between variables and constants, and the types of constants, i.e. 0x2f1u 0232562L 627489325762934692LL.
Read about overflow of signed and unsigned integers. Also the same things about floats.
Read about casting and order of ops. to avoid overflow, typedef and types like int32_t for improved portability
Did my own version of the message length program from the examples and programming Ex. 15.
Chapter 9:
Arrays. Having some trouble with exercise I tried, making a random walk with matrices, r_walk.c
Note to self: e-mail jim.
Here are the two C programs I wrote
during class.
/*
* looking at sizes of int
* and maxint
*
* On my (64bit) laptop :
$ make sizes
$ ./sizes
sizeof(int) = 4 bytes
= 32 bits
so max int is 2147483647
sizeof(long)= 8 bytes
*
*/
#include <stdio.h>
#include <math.h>
int main(){
short i;
unsigned long size = sizeof(int);
printf(" sizeof(int) = %lu bytes \n", size);
printf(" = %lu bits \n", 8*size);
printf(" so max int is %.0f \n", pow(2, (8*size-1)) - 1);
printf("\n");
printf(" sizeof(long)= %lu bytes \n", sizeof(long));
return 0;
}
/*
* mutual recursion in C
*
* The point is that the do_next() function
* needs to be declared (without its {...} implementation)
* before it's called .
*/
#include <stdio.h>
void do_next(int i);
void half(int i){
do_next(i/2);
}
void triple_add_one(int i){
do_next(3 * i + 1);
}
void do_next(int i){
printf(" %i \n", i);
if (i == 1)
return;
else if (i % 2 == 0)
half(i);
else
triple_add_one(i);
}
int main(){
int i = 27;
do_next(i);
return 0;
}