Chapter4
This commit is contained in:
parent
4e7fa1b23f
commit
0b7e3b6cb0
21
DeitelC/Chapter4/PrimeNums.c
Normal file
21
DeitelC/Chapter4/PrimeNums.c
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
33
DeitelC/Chapter4/example4-3.c
Normal file
33
DeitelC/Chapter4/example4-3.c
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
22
DeitelC/Chapter4/example4-7.c
Normal file
22
DeitelC/Chapter4/example4-7.c
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
15
DeitelC/Chapter4/example4-8.c
Normal file
15
DeitelC/Chapter4/example4-8.c
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
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
|
17
DeitelC/Chapter4/sumAndAverage.c
Normal file
17
DeitelC/Chapter4/sumAndAverage.c
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user