From: Steven Baltakatei Sandoval Date: Sat, 6 Aug 2022 06:12:26 +0000 (+0000) Subject: update(src/):Add tutorial test code X-Git-Url: https://zdv2.bktei.com/gitweb/BK-2023-05.git/commitdiff_plain/f6946e55ec99a9c95eff540e478886b33fae9443?ds=inline update(src/):Add tutorial test code --- diff --git a/src/20220804T2326Z..test.c b/src/20220804T2326Z..test.c new file mode 100644 index 0000000..2811d78 --- /dev/null +++ b/src/20220804T2326Z..test.c @@ -0,0 +1,28 @@ +/* Desc: + * Usage: ./test + * Ref/Attrib: [1] https://youtu.be/ix5jPkxsr7M?t=3072 + */ + +#include +#include + +int main() +{ + int age = 40; + double gpa = 3.6; + char grade = 'A'; // must use single-quotes + char phrase[100] = "baltakatei"; + + printf("\n"); + printf("age:%i\n", age); + printf("gpa:%f\n", gpa); // %f indicates float or double? + printf("phrase:%s\n", phrase); + printf("\n"); + + return 0; +}; + +/* + * Author: Steven Baltakatei Sandoval + * License: GPLv3+ + */ diff --git a/src/20220804T2340Z..test.c b/src/20220804T2340Z..test.c new file mode 100644 index 0000000..b8faa69 --- /dev/null +++ b/src/20220804T2340Z..test.c @@ -0,0 +1,29 @@ +/* Desc: + * Usage: ./test + * Ref/Attrib: [1] https://youtu.be/ix5jPkxsr7M?t=3072 + */ + +#include +#include + +int main() +{ + int favNum = 90; + char myChar = 'i'; + printf("\n"); + printf("Hello \"World\".\n"); + printf("%d\n", 500); // 'd' for digit? + printf("My favorite number is %d\n", 500); + printf("My favorite %s is %d\n", "number", 500); + printf("My favorite %s is %f\n", "number", 500.98764); // 'f' for float? + printf("My favorite %s is %d\n", "number", favNum); + printf("My favorite character is %c\n", myChar); + + printf("\n"); + return 0; +}; + +/* + * Author: Steven Baltakatei Sandoval + * License: GPLv3+ + */ diff --git a/src/20220804T2348Z..test.c b/src/20220804T2348Z..test.c new file mode 100644 index 0000000..9053509 --- /dev/null +++ b/src/20220804T2348Z..test.c @@ -0,0 +1,32 @@ +/* Desc: + * Usage: ./test + * Ref/Attrib: [1] https://youtu.be/ix5jPkxsr7M?t=3072 + */ + +#include +#include +#include + +int main() +{ + + int num = 6; + printf("%f\n", 3.141592); // 'f' for floating-point number + printf("%f\n", 5.0 * 9.5); // 'f' for floating-point number + printf("%f\n", 5 * 9.5); // int + float results in float + printf("%d\n", 5 / 4); // doesn't show decimals + printf("%f\n", 5 / 4.0); + printf("%d\n", num); // print an int variable + printf("%f\n", pow(4, 3)); // exponentiation; requires to be included + printf("%f\n", sqrt(36)); // square root + printf("%f\n", ceil(36.356)); // ceiilng; rounds up + printf("%f\n", floor(36.356)); // ceiilng; rounds down + + printf("\n"); + return 0; +}; + +/* + * Author: Steven Baltakatei Sandoval + * License: GPLv3+ + */ diff --git a/src/20220804T2352Z..test.c b/src/20220804T2352Z..test.c new file mode 100644 index 0000000..cc84c2f --- /dev/null +++ b/src/20220804T2352Z..test.c @@ -0,0 +1,29 @@ +/* Desc: + * Usage: ./test + * Ref/Attrib: [1] https://youtu.be/ix5jPkxsr7M?t=3072 + */ + +#include +#include + + +int main() +{ + /* asdf + * My Program + */ + + + /* + //This prints out text. + printf("Comments are fun."); + */ + + printf("\n"); + return 0; +}; + +/* + * Author: Steven Baltakatei Sandoval + * License: GPLv3+ + */ diff --git a/src/20220805T2317Z..test.c b/src/20220805T2317Z..test.c new file mode 100644 index 0000000..4775a32 --- /dev/null +++ b/src/20220805T2317Z..test.c @@ -0,0 +1,32 @@ +/* Desc: + * Usage: ./test + * Ref/Attrib: [1] https://youtu.be/ix5jPkxsr7M?t=3072 + */ + +#include +#include + + +int main() +{ + const int FAV_NUM = 5; + printf("%d\n", FAV_NUM); + // num = 8; + printf("%d\n", FAV_NUM); + + printf("%d", 90); + + + /* + //This prints out text. + printf("Comments are fun."); + */ + + printf("\n"); + return 0; +}; + +/* + * Author: Steven Baltakatei Sandoval + * License: GPLv3+ + */ diff --git a/src/20220805T2336Z..test.c b/src/20220805T2336Z..test.c new file mode 100644 index 0000000..3a54673 --- /dev/null +++ b/src/20220805T2336Z..test.c @@ -0,0 +1,40 @@ +/* Desc: + * Usage: ./test + * Ref/Attrib: [1] https://youtu.be/ix5jPkxsr7M?t=3072 + * [2] C: Multiple scanf's, when I enter in a value for one scanf it skips the second scanf https://stackoverflow.com/a/9562355 + */ + + +#include +#include + + +int main() +{ + int age; + printf("Enter your age: "); + scanf("%d", &age); // scanf is like opposite of printf + getchar(); // Need to run getchar() after each scanf() in order to clear + // scanf() input buffer for next scanf() command. + printf("You are %d years old\n", age); + + double gpa; + printf("Enter your gpa: "); + scanf("%lf", &gpa); // lf tells scanf you are looking for adouble + getchar(); + printf("Your GPA is %f\n", gpa); + + char grade; + printf("Enter your grade: "); + scanf("%c", &grade); // lf tells scanf you are looking for adouble + getchar(); + printf("Your grade is %c\n", grade); + + printf("\n"); + return 0; +}; + +/* + * Author: Steven Baltakatei Sandoval + * License: GPLv3+ + */ diff --git a/src/20220805T2340Z..test.c b/src/20220805T2340Z..test.c new file mode 100644 index 0000000..1e910ff --- /dev/null +++ b/src/20220805T2340Z..test.c @@ -0,0 +1,27 @@ +/* Desc: + * Usage: ./test + * Ref/Attrib: [1] https://youtu.be/ix5jPkxsr7M?t=3072 + * [2] C: Multiple scanf's, when I enter in a value for one scanf it skips the second scanf https://stackoverflow.com/a/9562355 + */ + + +#include +#include + + +int main() +{ + char name[20]; // storing string as an array of chars + printf("Enter your name: "); + scanf("%s", name); // lf tells scanf you are looking for adouble. drops chars after space. + //getchar(); + printf("Your name is %s\n", name); + + printf("\n"); + return 0; +}; + +/* + * Author: Steven Baltakatei Sandoval + * License: GPLv3+ + */ diff --git a/src/20220805T2344Z..test.c b/src/20220805T2344Z..test.c new file mode 100644 index 0000000..bc95507 --- /dev/null +++ b/src/20220805T2344Z..test.c @@ -0,0 +1,27 @@ +/* Desc: + * Usage: ./test + * Ref/Attrib: [1] https://youtu.be/ix5jPkxsr7M?t=3072 + * [2] C: Multiple scanf's, when I enter in a value for one scanf it skips the second scanf https://stackoverflow.com/a/9562355 + */ + + +#include +#include + + +int main() +{ + char name[256]; // storing string as an array of chars + printf("Enter your name: "); + fgets(name, 256, stdin); // fgets grabs whole line of text. exits when newline entered by user. includes newline in stored string. + //getchar(); + printf("Your name is %s\n", name); + + printf("\n"); + return 0; +}; + +/* + * Author: Steven Baltakatei Sandoval + * License: GPLv3+ + */ diff --git a/src/20220805T2348Z..test.c b/src/20220805T2348Z..test.c new file mode 100644 index 0000000..cf79fed --- /dev/null +++ b/src/20220805T2348Z..test.c @@ -0,0 +1,29 @@ +/* Desc: calculator to add two integers + * Usage: ./test + * Ref/Attrib: [1] https://youtu.be/ix5jPkxsr7M?t=3072 + * [2] C: Multiple scanf's, when I enter in a value for one scanf it skips the second scanf https://stackoverflow.com/a/9562355 + */ + + +#include +#include + + +int main() +{ + int num1; + int num2; + printf("Enter first number: "); + scanf("%d", &num1); + getchar(); + printf("Enter second number: "); + scanf("%d", &num2); + + printf("Answer: %d", num1 + num2); + return 0; +}; + +/* + * Author: Steven Baltakatei Sandoval + * License: GPLv3+ + */ diff --git a/src/20220806T0027Z..test.c b/src/20220806T0027Z..test.c new file mode 100644 index 0000000..a9e686f --- /dev/null +++ b/src/20220806T0027Z..test.c @@ -0,0 +1,36 @@ +/* Desc: + * Usage: ./test + * Ref/Attrib: [1] https://youtu.be/ix5jPkxsr7M?t=3072 + * [2] C: Multiple scanf's, when I enter in a value for one scanf it skips the second scanf https://stackoverflow.com/a/9562355 + */ + + +#include +#include + + +int main() +{ + char color[20]; + char pluralNoun[20]; + char celebrityF[20]; + char celebrityL[20]; + + printf("Enter a color: "); + scanf("%s", color); + printf("Enter a plural noun: "); + scanf("%s", pluralNoun); + printf("Enter a celebrity: "); + scanf("%s%s", celebrityF, celebrityL); + + printf("Roses are %s\n", color); + printf("%s are blue\n", pluralNoun); + printf("I love %s %s\n", celebrityF, celebrityL); + + return 0; +}; + +/* + * Author: Steven Baltakatei Sandoval + * License: GPLv3+ + */ diff --git a/src/20220806T0039Z..test.c b/src/20220806T0039Z..test.c new file mode 100644 index 0000000..947a572 --- /dev/null +++ b/src/20220806T0039Z..test.c @@ -0,0 +1,25 @@ +/* Desc: + * Usage: ./test + * Ref/Attrib: [0] C programming tutorial for beginners https://youtu.be/KJgsSFOSQv0?t=5512 + * [1] https://youtu.be/ix5jPkxsr7M?t=3072 + * [2] C: Multiple scanf's, when I enter in a value for one scanf it skips the second scanf https://stackoverflow.com/a/9562355 + */ + + +#include +#include + + +int main() +{ + int luckyNumbers[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29}; + luckyNumbers[3] = 200; + printf("%d", luckyNumbers[3]); + + return 0; +}; + +/* + * Author: Steven Baltakatei Sandoval + * License: GPLv3+ + */ diff --git a/src/20220806T0611Z..test.c b/src/20220806T0611Z..test.c new file mode 100644 index 0000000..1f55437 --- /dev/null +++ b/src/20220806T0611Z..test.c @@ -0,0 +1,30 @@ +/* Desc: Function example + * Usage: ./test + * Ref/Attrib: [0] C programming tutorial for beginners https://youtu.be/KJgsSFOSQv0?t=5814 + * [1] https://youtu.be/ix5jPkxsr7M?t=3072 + * [2] C: Multiple scanf's, when I enter in a value for one scanf it skips the second scanf https://stackoverflow.com/a/9562355 + */ + + +#include +#include + +void sayHi(char name[], int age){ + printf("Hello %s, you are %d.\n", name, age); +}; + +int main() +{ + printf("Top\n"); + sayHi("Balta Katei", 671); + sayHi("Kodaw Kuori", 350); + sayHi("Samki Licui", 21); + printf("bottom\n"); + return 0; +}; + + +/* + * Author: Steven Baltakatei Sandoval + * License: GPLv3+ + */ diff --git a/src/monitor.sh b/src/monitor.sh new file mode 100644 index 0000000..5eace48 --- /dev/null +++ b/src/monitor.sh @@ -0,0 +1,6 @@ +#!/bin/bash +date --iso-8601=ns; +TIMEFORMAT='real: %3R user: %3U sys: %3S cpu: %P'; time gcc -o test test.c; +TIMEFORMAT='real: %3R user: %3U sys: %3S cpu: %P'; time ./test; +ls -al test.c +ls -al test diff --git a/src/test b/src/test new file mode 100755 index 0000000..aa2572f Binary files /dev/null and b/src/test differ diff --git a/src/test.c b/src/test.c index b08fbb0..15ff954 100644 --- a/src/test.c +++ b/src/test.c @@ -1,12 +1,22 @@ -/* - * Author: Steven Baltakatei Sandoval - * Purpose: Test my Emacs C setup - * Copyright 2022 +/* Desc: Return example + * Usage: ./test + * Ref/Attrib: [0] C programming tutorial for beginners https://youtu.be/KJgsSFOSQv0?t=6338 + * [1] https://youtu.be/ix5jPkxsr7M?t=3072 + * [2] C: Multiple scanf's, when I enter in a value for one scanf it skips the second scanf https://stackoverflow.com/a/9562355 */ + #include +#include + int main() { - puts("Hi, my name is 'Baltakatei'."); + return 0; -} +}; + + +/* + * Author: Steven Baltakatei Sandoval + * License: GPLv3+ + */ diff --git a/src/test3 b/src/test3 new file mode 100755 index 0000000..d990091 Binary files /dev/null and b/src/test3 differ diff --git a/src/test4 b/src/test4 new file mode 100755 index 0000000..a96ae53 Binary files /dev/null and b/src/test4 differ diff --git a/src/test5 b/src/test5 new file mode 100755 index 0000000..50040a8 Binary files /dev/null and b/src/test5 differ