commit fe5ce2a18efe7243bd44b285754b3be32ae06df1 Author: BuildTools Date: Sun Jan 3 16:05:51 2021 -0500 Init Commit Signed-off-by: BuildTools diff --git a/README.md b/README.md new file mode 100644 index 0000000..4c5f807 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +Learning C diff --git a/a.out b/a.out new file mode 100755 index 0000000..c09ad3f Binary files /dev/null and b/a.out differ diff --git a/hello_world.c b/hello_world.c new file mode 100644 index 0000000..8ebe5ef --- /dev/null +++ b/hello_world.c @@ -0,0 +1,12 @@ +/* + * Learning C with some easy code + * Hello World + */ + +#include +#include + +int main() { + printf("Hello world!\n"); + return EXIT_SUCCESS; +} diff --git a/sum.c b/sum.c new file mode 100644 index 0000000..5ea92f2 --- /dev/null +++ b/sum.c @@ -0,0 +1,36 @@ +/* + * Learning C with some easy code + * Sum of Input + */ + +#include +#include +#define TRUE 1 + +int main() { + int size = 1; + int sum = 0; + int pos = 0; + int* arr = malloc(size * sizeof(int)); + + while(TRUE) { + printf("Enter a number: "); + scanf("%d", &(arr[pos])); + printf("Num: %d\n", arr[pos]); + if( arr[pos] == 0 ) { + break; + } + size++; + int* new_arr = realloc(arr, size * sizeof(int)); + arr = new_arr; + pos++; + } + + for (int i = 0; i < size; i++) { + sum += arr[i]; + } + + printf("You sum is: %d\n", sum); + + return EXIT_SUCCESS; +} diff --git a/template.c b/template.c new file mode 100644 index 0000000..4badb31 --- /dev/null +++ b/template.c @@ -0,0 +1,11 @@ +/* + * Learning C with some easy code + * Hello World + */ + +#include + +int main() { + printf("Hello world!"); + return 0; +}