CS 2073 Engineering Programming
|
You should also review your work for the programming assignments:
int time = 74747; /8 or some other value in seconds */ int hours = ...; /* fill in for ... */ int minutes = ...; /* fill in for ... */ int seconds = ...; /* fill in for ... */ /* print the answer in the form: 74747 seconds is 20 hours, 45 minutes, 47 seconds. */
int i = 1;
int sum = 0;
while (i < 10) {
sum = sum + i*i;
i++;
}
printf("sum: %i", sum);
int k;
for (k = 10; k >= 1; k--) {
printf("%i", k);
if (k != 10) printf(", ");
}
printf("\n");
1 + 1/22 + 1/32 + 1/42 + 1/52 + ...
a0 = 2*sqrt(3); b0 = 3; a1 = 2*a0*b0/(a0 + b0); b1 = sqrt(a1*b0);
Then replace a1 and b1 by a0 and b0, and repeat the last two equations. Keep repeating until a1 and b1 are within 1.0e-15 of one another. The final answer should be the average of a1 and b1.
char *months[] = {"January",
"February", "March", "April", "May",
"June", "July", "August", "September",
"October", "November", "December"};
In this case, months[1], months[2], ... are each strings that can be printed with a %s format. First use a for loop to print them.
Now create a array of random numbers of the same size as months:
#include <stdlib.h> #include <time.h> double ran[12]; int i; for (i = 0; i < 12; i++) ran[i] = rand()/(double)RAND_MAX;
Finally, sort the array ran into order, carrying the array months along with it. The result is to randomize the order of the months.
Then the formal parameter uses a * to declare the formal parameter as a pointer. Inside the code, use is often made of the * operator (dereference operator) to refer to the value that the pointer is pointing to.
Notice the very confusing aspect: a * is used both to declare a variable as a pointer and to retrieve the value pointed to.