diff --git a/DeitelC/Chapter3/IsPrime.c b/DeitelC/Chapter3/IsPrime.c index f89f9ff..6fb9e58 100644 --- a/DeitelC/Chapter3/IsPrime.c +++ b/DeitelC/Chapter3/IsPrime.c @@ -6,20 +6,20 @@ int count = 0; while (a < number) { if(number%a == 0) { - count += 1; - a++; - } else { - a++; + printf("%s\n", "No it isn't a Prime"); + return; } + a++; } if(count == 1) { printf("%s\n", "Yes it's a Prime"); } else { - printf("%s\n", "No it isn't a Prime"); + } } + int main(void) { int number; printf("%s\n", "Enter a integer!"); diff --git a/DeitelC/Chapter3/a.exe b/DeitelC/Chapter3/a.exe deleted file mode 100644 index e4b3924..0000000 Binary files a/DeitelC/Chapter3/a.exe and /dev/null differ diff --git a/DeitelC/Chapter4/1to20.c b/DeitelC/Chapter4/1to20.c new file mode 100644 index 0000000..7489484 --- /dev/null +++ b/DeitelC/Chapter4/1to20.c @@ -0,0 +1,22 @@ +#include + +int main(void){ + int counter = 1; + while(counter<= 20) { + if(counter%5==0) { + printf("%d\t",counter); + counter++; + } else { + counter++; + } + } + printf("\n"); + for(int x = 1; x<=20 ;++x) { + if (x%5==0) { + printf("%d\t", x); + } else { + + } + } + return 0; +} \ No newline at end of file diff --git a/DeitelC/Chapter4/CelciusToFahrenheit.c b/DeitelC/Chapter4/CelciusToFahrenheit.c new file mode 100644 index 0000000..8fc14ea --- /dev/null +++ b/DeitelC/Chapter4/CelciusToFahrenheit.c @@ -0,0 +1,15 @@ +#include + +int CelciusConvert(int c) { + int f; + f = ((c*9)/5)+32; +return f; +} + +int main(void) { + int c; + int f; + printf("%s\n", "Enter Celcius degree!"); + scanf("%d", &c); + printf("%d %s %d",c, " Celcius equals to Fahrenheit: ", CelciusConvert(c)); +} \ No newline at end of file diff --git a/DeitelC/Chapter4/a.exe b/DeitelC/Chapter4/a.exe index 9ef15aa..8c66b27 100644 Binary files a/DeitelC/Chapter4/a.exe and b/DeitelC/Chapter4/a.exe differ diff --git a/DeitelC/Chapter4/check.c b/DeitelC/Chapter4/check.c new file mode 100644 index 0000000..db8bfbc --- /dev/null +++ b/DeitelC/Chapter4/check.c @@ -0,0 +1,9 @@ +#include + +int main() { + int i = 5, j = 7, k = 4, m = -2; + //printf("%d", i >= 5 && j > 4); + /*printf("%d", !m && k > m); + printf("%d", !k || m); */ + printf("%d", !2); +} \ No newline at end of file diff --git a/DeitelC/Chapter4/test1.c b/DeitelC/Chapter4/test1.c new file mode 100644 index 0000000..8153011 --- /dev/null +++ b/DeitelC/Chapter4/test1.c @@ -0,0 +1,17 @@ +#include + int main() + { + int x, i, j; + // prompt user for input + printf("%s", "Enter an integer in the range 1-20:"); + scanf("%d", &x); // read values for x + for (i = 1; i <= x; i++) { // count from 1 to x + for (j = 1; j <= x; j++) { // count from 1 to x + if (j==i) + printf("%c",'@'); // output @ + else + printf(" "); + } // end inner for + printf("\n"); + } // end outer for + } // end of main \ No newline at end of file diff --git a/a.exe b/a.exe new file mode 100644 index 0000000..eb05af6 Binary files /dev/null and b/a.exe differ diff --git a/test1.c b/test1.c new file mode 100644 index 0000000..6103fc6 --- /dev/null +++ b/test1.c @@ -0,0 +1,24 @@ +#include + +int main(void){ + +int num; +int e = 1; +int decimal = 0; + +printf("%s\n", "Enter UNSIGNED BINARY! to convert decimal"); +scanf("%d", &num); +int temp = num; + +while (temp) { + int last = temp % 10; + temp = temp / 10; + + decimal += last * e; + e = e * 2; + +} +printf("%s %d\n", "Decimal: ", decimal); + + return 0; +} diff --git a/test2.c b/test2.c new file mode 100644 index 0000000..2bf8074 --- /dev/null +++ b/test2.c @@ -0,0 +1,13 @@ +#include + +int main() { +int n = 4, a = 1; +int i, c; + for (i = 1; i <=n; i++) { + for (c = 1; c <= i; c++) { + printf("%d", a); + a++; + } + printf("\n"); + } +} \ No newline at end of file