Aug 042009
I’m noticing that these problems aren’t as much about learning the language as I’d have thought. They’re fairly simple tasks.
Anyways, here’s the second problem’s solution:
/*
* File: main.c
* Author: david.kowis
*
* Created on August 4, 2009, 7:48 AM
*/
#include <stdio.h>
#include <stdlib.h>
/*
*
*/
int main(int argc, char** argv) {
int last = 1, secondLast = 0, current = 0;
int max = 0, min = 0;
int x;
int numbers[10];
//Fibbonaci sequence
printf("0, 1, ");
for (x = 1; x < 100; x++) {
current = last + secondLast;
printf("%u, ", current);
secondLast = last;
last = current;
}
printf("\n");
srand(time(NULL));
//initialize random list
printf("Random numbers to find max and min of\n");
for (x = 0; x < 10; x++) {
numbers[x] = rand() % 1000;
printf("%u, ", numbers[x]);
}
printf("\n");
max = numbers[0];
min = numbers[0];
printf("Finding the max and min...\n");
for (x = 0; x < 10; x++) {
if (min > numbers[x]) {
min = numbers[x];
}
if (max < numbers[x]) {
max = numbers[x];
}
}
printf("Maximum: %u Minimum %u\n\n", max, min);
return (EXIT_SUCCESS);
}

