diff --git a/DeitelC/Chapter4/PrimeNums.c b/DeitelC/Chapter4/PrimeNums.c new file mode 100644 index 0000000..eaf61ec --- /dev/null +++ b/DeitelC/Chapter4/PrimeNums.c @@ -0,0 +1,21 @@ +#include + +int main(void) { + puts("Show all prime numbers until: "); + int i; + if(scanf("%d", &i) != 1 || i < 2) { + puts("ERROR, entered integer NOT valid!"); + } + + for(int y = 2; y < i; y++) { + int counter = 0; + for(int a = 2; a < y; a++) { + if(y % a == 0) { + counter = 1; + } + } + if (!counter) { + printf("%d\t", y); + } + } +} diff --git a/DeitelC/Chapter4/a.out b/DeitelC/Chapter4/a.out index db8e620..d707f01 100644 Binary files a/DeitelC/Chapter4/a.out and b/DeitelC/Chapter4/a.out differ diff --git a/DeitelC/Chapter4/example4-3.c b/DeitelC/Chapter4/example4-3.c new file mode 100644 index 0000000..13bd5e1 --- /dev/null +++ b/DeitelC/Chapter4/example4-3.c @@ -0,0 +1,33 @@ +#include +#include + +int main(void){ + int sum = 0; + for(int i = 1; i <= 99; i += 2) { + sum += i; +} + +printf("%s%d\n","Sum of 1-99 odd numbers: ", sum); + +printf("%-15.1f\n", 333.546372); +printf("%-15.2f\n", 333.546372); +printf("%-15.3f\n", 333.546372); +printf("%-15.4f\n", 333.546372); +printf("%-15.5f\n", 333.546372); +printf("%10.2f\n", pow(2.5,3)); + +int counter = 1; + +while (counter <= 20) { + if(counter % 5 == 0) { + printf("%d\n", counter); + } else { + printf("%d\t", counter); + } + + ++counter; +} + + +return 0; +} diff --git a/DeitelC/Chapter4/example4-7.c b/DeitelC/Chapter4/example4-7.c new file mode 100644 index 0000000..d801f54 --- /dev/null +++ b/DeitelC/Chapter4/example4-7.c @@ -0,0 +1,22 @@ +#include + +int main(void) { + for(int x = 1; x <= 13; x += 2) { + printf("%d\t",x); + } + puts(""); + for(int x = 2; x <= 17; x += 3) { + printf("%d\t",x); + } + puts(""); + for(int x = 30; x >= -30; x -= 10) { + printf("%d\t",x); + } + puts(""); + for(int x = 15; x <= 55; x += 8) { + printf("%d\t",x); + } + puts(""); + + return 0; +} diff --git a/DeitelC/Chapter4/example4-8.c b/DeitelC/Chapter4/example4-8.c new file mode 100644 index 0000000..3d5e7e8 --- /dev/null +++ b/DeitelC/Chapter4/example4-8.c @@ -0,0 +1,15 @@ +#include +int main() + { +int x, i, j; +printf("%s", "Enter an integer in the range 1-20:"); +scanf("%d", &x); // read values for x + for (i = 1; i <= x; i++) { +for (j = 1; j <= x; j++) { +if (j==i) + printf("%c",'@'); // output @ 12 + else + printf(" "); } // end inner for 15 +printf("\n"); + } // end outer for 17 +} // end of main diff --git a/DeitelC/Chapter4/sumAndAverage.c b/DeitelC/Chapter4/sumAndAverage.c new file mode 100644 index 0000000..9541de2 --- /dev/null +++ b/DeitelC/Chapter4/sumAndAverage.c @@ -0,0 +1,17 @@ +#include + +int main(void) { + int x = 0, counter = 0; + scanf("%d", &x); + + for(int t = 0; t < x; t++){ + int i; + scanf("%d", &i); + counter += i; + } + + printf("%d\n", counter/x); + +return 0; +} +