Merge branch 'master' of https://git.cscherr.de/PlexSheep/c-basic
This commit is contained in:
commit
1d2ef5ae51
6 changed files with 49 additions and 15 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -62,3 +62,4 @@ build
|
||||||
CMakeCache.txt
|
CMakeCache.txt
|
||||||
Makefile
|
Makefile
|
||||||
src/huffman/testfiles
|
src/huffman/testfiles
|
||||||
|
data
|
||||||
|
|
|
@ -21,6 +21,7 @@ add_executable( echochar src/echochar.c )
|
||||||
add_executable( euler src/euler.c )
|
add_executable( euler src/euler.c )
|
||||||
add_executable( factorial src/factorial.c )
|
add_executable( factorial src/factorial.c )
|
||||||
add_executable( fail src/fail.c )
|
add_executable( fail src/fail.c )
|
||||||
|
add_executable( fib src/fib.c )
|
||||||
add_executable( fread src/fread.c )
|
add_executable( fread src/fread.c )
|
||||||
add_executable( hello-world src/hello-world.c )
|
add_executable( hello-world src/hello-world.c )
|
||||||
add_executable( options src/options.c )
|
add_executable( options src/options.c )
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Install script for directory: /home/plex/Documents/code/c/c-basic
|
# Install script for directory: /home/cscherr/Documents/code/c/c-basic
|
||||||
|
|
||||||
# Set the install prefix
|
# Set the install prefix
|
||||||
if(NOT DEFINED CMAKE_INSTALL_PREFIX)
|
if(NOT DEFINED CMAKE_INSTALL_PREFIX)
|
||||||
|
@ -29,7 +29,7 @@ endif()
|
||||||
|
|
||||||
# Install shared libraries without execute permission?
|
# Install shared libraries without execute permission?
|
||||||
if(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)
|
if(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)
|
||||||
set(CMAKE_INSTALL_SO_NO_EXE "0")
|
set(CMAKE_INSTALL_SO_NO_EXE "1")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Is this installation the result of a crosscompile?
|
# Is this installation the result of a crosscompile?
|
||||||
|
@ -50,5 +50,5 @@ endif()
|
||||||
|
|
||||||
string(REPLACE ";" "\n" CMAKE_INSTALL_MANIFEST_CONTENT
|
string(REPLACE ";" "\n" CMAKE_INSTALL_MANIFEST_CONTENT
|
||||||
"${CMAKE_INSTALL_MANIFEST_FILES}")
|
"${CMAKE_INSTALL_MANIFEST_FILES}")
|
||||||
file(WRITE "/home/plex/Documents/code/c/c-basic/${CMAKE_INSTALL_MANIFEST}"
|
file(WRITE "/home/cscherr/Documents/code/c/c-basic/${CMAKE_INSTALL_MANIFEST}"
|
||||||
"${CMAKE_INSTALL_MANIFEST_CONTENT}")
|
"${CMAKE_INSTALL_MANIFEST_CONTENT}")
|
||||||
|
|
19
src/euler.c
19
src/euler.c
|
@ -20,7 +20,7 @@ double factorial(double i) {
|
||||||
|
|
||||||
// someone said i need 2 for loops. Totally wrong?
|
// someone said i need 2 for loops. Totally wrong?
|
||||||
for(int j=1;j<given;j++){
|
for(int j=1;j<given;j++){
|
||||||
|
|
||||||
p *= j;
|
p *= j;
|
||||||
//printf("[DEBUG]p is %f, j is %d\n", p, j);
|
//printf("[DEBUG]p is %f, j is %d\n", p, j);
|
||||||
}
|
}
|
||||||
|
@ -35,16 +35,15 @@ int main(int argc, char *argv[]){
|
||||||
int k = 0;
|
int k = 0;
|
||||||
int end = 0;
|
int end = 0;
|
||||||
while(!end){
|
while(!end){
|
||||||
res += euler(k);
|
res += euler(k);
|
||||||
printf("%f, %f\n", res, lres);
|
printf("%f, %f\n", res, lres);
|
||||||
if(res==lres)
|
if(res==lres)
|
||||||
end = 1;
|
end = 1;
|
||||||
else {
|
else {
|
||||||
lres = res;
|
lres = res;
|
||||||
}
|
}
|
||||||
k++;
|
k++;
|
||||||
}
|
}
|
||||||
printf("calculated eulers number as %f\n", res);
|
printf("calculated eulers number as %f\n", res);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
29
src/fib.c
Normal file
29
src/fib.c
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
const int START_VALUES[2] = {0, 1};
|
||||||
|
const int LIMIT = 90;
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
if (argc != 2) {
|
||||||
|
printf("usage: %s MAX_NUMBER\n", argv[0]);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
int max = atoi(argv[1]);
|
||||||
|
if (max > LIMIT) {
|
||||||
|
printf("C does not provide a datatype large enough to compute fibonacci numbers > %d. (%d)\n", LIMIT, max);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
uintmax_t* nums = malloc(max * sizeof(uintmax_t));
|
||||||
|
nums[0] = START_VALUES[0];
|
||||||
|
nums[1] = START_VALUES[1];
|
||||||
|
|
||||||
|
for(int i = 2; i < max+1; i++) {
|
||||||
|
nums[i] = nums[i-2] + nums[i-1];
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i = 0; i < max+1; i++) {
|
||||||
|
printf("%02d. %ju\n", i, nums[i]);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,9 +1,13 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
int main(void)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
char filename[] = "file.txt";
|
if (argc != 2) {
|
||||||
|
printf("usage: %s FILE", argv[0]);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
char* filename = argv[1];
|
||||||
char buf[2];
|
char buf[2];
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue