From 7d6e8e62cbc5b9cc24b43e06df306d5373d701c4 Mon Sep 17 00:00:00 2001 From: Ivan Mahonin Date: Jan 19 2019 06:32:37 +0000 Subject: c: console --- diff --git a/c/console/average/average.c b/c/console/average/average.c new file mode 100644 index 0000000..db431f2 --- /dev/null +++ b/c/console/average/average.c @@ -0,0 +1,17 @@ +#include + +int main() { + int h[10]; + for(int i = 0; i < 10; ++i) { + printf("Enter height %d: ", i+1); + scanf("%d", &h[i]); + } + + int sum = 0; + for(int i = 0; i < 10; ++i) + sum += h[i]; + float avg = sum / 10.f; + + printf("Average height is %f\n", avg); + return 0; +} diff --git a/c/console/box-and-hole/boxandhole.c b/c/console/box-and-hole/boxandhole.c new file mode 100644 index 0000000..00a8aab --- /dev/null +++ b/c/console/box-and-hole/boxandhole.c @@ -0,0 +1,35 @@ +#include + +int main() { + int a, b, c; + printf("Enter box size (a b c): "); + scanf("%d%d%d", &a, &b, &c); + + int x, y; + printf("Enter hole size (x y):"); + scanf("%d%d", &x, &y); + + int pass = 0; + if (a < x && b < y) pass = 1; + if (b < x && c < y) pass = 1; + if (c < x && a < y) pass = 1; + + if (b < x && a < y) pass = 1; + if (c < x && b < y) pass = 1; + if (a < x && c < y) pass = 1; + + /* or coding conditions in other way: + int pass = (a < x && b < y) + || (b < x && c < y) + || (c < x && a < y) + || (b < x && a < y) + || (c < x && b < y) + || (a < x && c < y); + */ + + if (pass) + printf("Will pass trought\n"); + else + printf("Box too large\n"); + return 0; +} diff --git a/c/console/expressions/expressions.c b/c/console/expressions/expressions.c new file mode 100644 index 0000000..ea2ad56 --- /dev/null +++ b/c/console/expressions/expressions.c @@ -0,0 +1,21 @@ +#include +#include + +int main() { + float a = 10.f, b = 15.f, c = 20.f; + float result; + + result = (1.f/4.f)*sqrtf((a+b+c)*(b+c-a)*(a+c-b)*(a+b-c)); + printf( "Area of triangle with sides %f, %f and %f is %f\n", + a, b, c, result ); + + result = (1.f/3.f)*M_PI*a*(b*b); + printf( "Volume of cone with height %f and radius %f is %f\n", + a, b, result ); + + result = (4.f/3.f)*M_PI*a*b*c; + printf( "Volume of ellipsoid with radiuses %f, %f and %f is %f\n", + a, b, c, result ); + + return 0; +} diff --git a/c/console/hello-world/helloworld.c b/c/console/hello-world/helloworld.c new file mode 100644 index 0000000..dafadc7 --- /dev/null +++ b/c/console/hello-world/helloworld.c @@ -0,0 +1,6 @@ +#include + +int main() { + printf("Hello World!\n"); + return 0; +} diff --git a/c/console/readme b/c/console/readme new file mode 100644 index 0000000..555cbcc --- /dev/null +++ b/c/console/readme @@ -0,0 +1,2 @@ +GCC commandline to compile each example is: + gcc -lm *.c diff --git a/c/console/sum/sum.c b/c/console/sum/sum.c new file mode 100644 index 0000000..b917f2f --- /dev/null +++ b/c/console/sum/sum.c @@ -0,0 +1,16 @@ +#include + +int main() { + int a, b, c; + + printf("Enter A: "); + scanf("%d", &a); + + printf("Enter B: "); + scanf("%d", &b); + + c = a + b; + printf("%d + %d = %d\n", a, b, c); + + return 0; +} diff --git a/c/console/support/support.c b/c/console/support/support.c new file mode 100644 index 0000000..d292999 --- /dev/null +++ b/c/console/support/support.c @@ -0,0 +1,46 @@ +#include +#include + +int main() { + char s[10]; + + printf("Have you any problem? (yes/no)\n"); + scanf("%5s", s); + while (strcmp(s, "yes") == 0) { + printf("Have you a problem with electronic devices? (yes/no)\n"); + scanf("%5s", s); + if (strcmp(s, "yes") == 0) { + printf("Have you a problem with TV? (yes/no)\n"); + scanf("%5s", s); + if (strcmp(s, "yes") == 0) { + printf("You must to go to TV master\n"); + } else { + printf("Have you a problem with computer? (yes/no)\n"); + scanf("%5s", s); + if (strcmp(s, "yes") == 0) + printf("You must go to sysadmin\n"); + else + printf("I am sorry, I cannot help you.\n"); + } + } else { + printf("Have you a problem with teapot? (yes/no)\n"); + scanf("%5s", s); + if (strcmp(s, "yes") == 0) { + printf("Was you teapot broken? (yes/no)\n"); + scanf("%5s", s); + if (strcmp(s, "yes") == 0) + printf("You must buy our super glue\n"); + else + printf("I am sorry, I cannot help you.\n"); + } else { + printf("I am sorry, I cannot help you.\n"); + } + } + + printf("Have you other problems? (yes/no)\n"); + scanf("%5s", s); + } + + printf("Good bye\n"); + return 0; +} diff --git a/c/console/talk/talk.c b/c/console/talk/talk.c new file mode 100644 index 0000000..7338cfe --- /dev/null +++ b/c/console/talk/talk.c @@ -0,0 +1,21 @@ +#include + +int main() { + char say[100], name[100]; + + printf("Hello!\n"); + scanf("%99s", say); + + printf("What is your name?\n"); + scanf("%99s", name); + + printf("Nice to meet you, %s\n", name); + printf("How are you?\n"); + scanf("%99s", say); + + printf("Oh.. program ends\n"); + printf("Good bye, %s\n", name); + scanf("%99s", say); + + return 0; +}