diff --git a/helloworld/elementary_10.c b/helloworld/elementary_10.c new file mode 100644 index 0000000..ce443d1 --- /dev/null +++ b/helloworld/elementary_10.c @@ -0,0 +1,28 @@ +#include +#include +int main() { + + time_t s, val = 1; + struct tm* current_time; + + s = time(NULL); + + current_time = localtime(&s); + printf("Current year = %d\n",(current_time->tm_year + 1900)); + int current_year = current_time->tm_year + 1900; + int next_leap_year = 4 - current_year % 4; + int leap_year = current_year + next_leap_year; + + for (int i = 0; i < 20; i++){ + if (leap_year % 100 == 0){ + i--; + } + else { + printf("%d, ", leap_year); + } + leap_year = leap_year + 4; + } + return 0; +} + +//2920-ig használható, később tévesen kihagyja a 3000-et \ No newline at end of file diff --git a/helloworld/elementary_10_fura.c b/helloworld/elementary_10_fura.c new file mode 100644 index 0000000..54300e6 --- /dev/null +++ b/helloworld/elementary_10_fura.c @@ -0,0 +1,39 @@ +#include +#include +int main() +{ + time_t s, val = 1; + struct tm* current_time; + + s = time(NULL); + + current_time = localtime(&s); + + printf("Day of the month = %d\n",current_time->tm_mday); + printf("Day in this year = %d\n",current_time->tm_yday); + printf("Day in this week = %d\n",current_time->tm_wday); + printf("Month of this year = %d\n",(current_time->tm_mon + 1)); + printf("Current year = %d\n",(current_time->tm_year + 1900)); + printf("hour:min:sec = %02d:%02d:%02d\n", + current_time->tm_hour, + current_time->tm_min, + current_time->tm_sec); + +/* int current_year = current_time->tm_year + 1900; + int next_leap_year = 4 - current_year % 4; + int leap_year = current_year + next_leap_year; + + for (int i = 0; i< 20; i++){ + if (leap_year % 100 == 0){ + i--; + } + else { + printf("%d, ", leap_year); + } + leap_year = leap_year + 4; + }*/ + + + return 0; +} + diff --git a/helloworld/elementary_11.c b/helloworld/elementary_11.c new file mode 100644 index 0000000..1e018e6 --- /dev/null +++ b/helloworld/elementary_11.c @@ -0,0 +1,22 @@ +//Write a program that computes the sum of an alternating series where each element +// of the series is an expression of the form ((-1)^{k+1})/(2 * k-1) +//for each value of k from 1 to a million, multiplied by 4. +//Or, in more mathematical notation +// 4\cdot \sum_{k=1}^{10^6} \frac{(-1)^{k+1}}{2k-1} = 4\cdot(1-1/3+1/5-1/7+1/9-1/11\ldots) + +#include +#include + +int main(){ + + double sum = 0; + for (double k = 1; k<= 1000000; k++){ + sum = sum + (pow (-1, k)/(2*k-1)); + printf("\nSum*4 is 1-%f-ig: %f", k, sum*4); + } + return 0; +} + +//double pow(double x, double y); +//Here, the value of the double variable x is raised to the power of y. +//The pow() function returns the result in the double data type. \ No newline at end of file diff --git a/helloworld/elementary_2_3.c b/helloworld/elementary_2_3.c new file mode 100644 index 0000000..8a0416b --- /dev/null +++ b/helloworld/elementary_2_3.c @@ -0,0 +1,22 @@ +#include + +int main() { + + char name [100]; /* define name */ + + setbuf(stdout, NULL); + + printf("Hogy hívnak? "); + scanf("%s", &name); + + if ( name == "Alice" || name == "Bob") { + + setbuf(stdout, NULL); + printf("Üdvözöllek, %s!", name); + } + + printf("%s!", name); + printf ("%d\n", name == "Bob"); + + return 0; +} diff --git a/helloworld/elementary_4.c b/helloworld/elementary_4.c new file mode 100644 index 0000000..4b11a0a --- /dev/null +++ b/helloworld/elementary_4.c @@ -0,0 +1,18 @@ +#include + +int main() { + + int szam; + int osszeg; + + setbuf(stdout, NULL); + printf("Írj egy számot: "); + scanf("%d", &szam); + + osszeg = (1+szam)*szam/2; // persze lehetett volna nagyon idétlen ciklussal is megoldani, de ez elegánsabb megoldásnak tűnt :-) + setbuf(stdout, NULL); + printf("A számok összege 1-%d-ig:%d", szam, osszeg); + + + return 0; +} diff --git a/helloworld/elementary_4_5.c b/helloworld/elementary_4_5.c new file mode 100644 index 0000000..f85ed3e --- /dev/null +++ b/helloworld/elementary_4_5.c @@ -0,0 +1,24 @@ +#include + +int main() { + + int szam; + int osszeg = 0; + + setbuf(stdout, NULL); + printf("Írj egy számot: "); + scanf("%d", &szam); + + // és akkor most legyen itt ciklussal, mert erre nincs matematikai képlet, bár gondolkozom rajta :-) + + int i; + for (i = 1; i <= szam; i++) { + if (i % 3 == 0 || i % 5 == 0) { + osszeg = osszeg + i; + } + } + setbuf(stdout, NULL); + printf("A hárommal vagy öttel osztható számok összege 1-%d-ig:%d", szam, osszeg); + return 0; +} +// kész \ No newline at end of file diff --git a/helloworld/elementary_6.c b/helloworld/elementary_6.c new file mode 100644 index 0000000..554b3c1 --- /dev/null +++ b/helloworld/elementary_6.c @@ -0,0 +1,35 @@ +#include + +int main() { + + int szam = 0; + int osszeg = 0; + int szorzat = 1; + char dontes = 'p'; + + setbuf(stdout, NULL); + + printf("Írj egy számot: "); + scanf("%d", &szam); + + printf("A számok összegét (s) vagy szorzatát (p) számoljam ki 1-től n-ig? "); + scanf(" %c", &dontes); + printf("%c", dontes); + + while (dontes != 's' && dontes !='p') { + printf("Kérlek nyomj s-t vagy p-t!\n"); + scanf("%c", &dontes); + } + if (dontes == 's') { + osszeg = (1 + szam)*szam/2; + printf("A számok összege 1-%d-ig:%d\n", szam, osszeg); + } + if (dontes == 'p') { + for (int i = 1; i <= szam; i++) { + szorzat = szorzat * i; + } + printf("A számok produktuma 1-%d-ig:%d\n", szam, szorzat); + } + return 0; +} +//most jól fut diff --git a/helloworld/elementary_7.c b/helloworld/elementary_7.c new file mode 100644 index 0000000..c6d003d --- /dev/null +++ b/helloworld/elementary_7.c @@ -0,0 +1,40 @@ +#include +#include + +// először is korlátozzuk a számot, különben belehalunk a várakozásba, +// hiszen nagyon sok prim szám van még INT tartományban is + +/*int is_prime(int szam, int i) { + + + return prime +}*/ + +int main() { + int szam; + int hatar; + int i; + int prime; + + setbuf(stdout, NULL); + printf("Meddig terjedjen a primek kiírása? "); + scanf("%d", &hatar); + + printf("2\n"); + for(szam = 3; szam <= hatar; szam = szam + 2) { + prime=0; + for(i = 2; i <= sqrt(szam+1); i++) { + if(szam % i ==0) { // akkor nem prim, menj a következő osztóra + prime = 1; + break; + } + // minden más esetben menj a következő osztóra + } + if (prime == 0) { + setbuf(stdout, NULL); + printf("%d\n", szam); //kiíratom vele, hogy prim-e, hogy lássam, hol van a baj + } + } + + return 0; +} \ No newline at end of file diff --git a/helloworld/elementary_8.c b/helloworld/elementary_8.c new file mode 100644 index 0000000..03ddb33 --- /dev/null +++ b/helloworld/elementary_8.c @@ -0,0 +1,24 @@ +#include + + +// ez tképpen a 7-es feladat, csak benéztem a számot + +int main(){ + + int i; + int j; + + printf("A szorzótábla\n "); + + for(i = 1; i <= 12; i++){ + setbuf(stdout, NULL); + printf("\nAz %d-s szorzótábla:\n", i); + for(j = 1; j <= 12; j++){ + printf("%d * %d = %d\n", j, i, i*j); + } + } + + return 0; +} + +//kész \ No newline at end of file diff --git a/helloworld/elementary_9.c b/helloworld/elementary_9.c new file mode 100644 index 0000000..2f50ec0 --- /dev/null +++ b/helloworld/elementary_9.c @@ -0,0 +1,42 @@ +#include +#include + +int main(int argc, char *argv[]) +{ + int a; + srand(time(NULL)); + a = rand() % 100 + 1; + + int number; + int old_number = 0; + int trials = 0; + + setbuf(stdout, NULL); + printf(" %d", a); + printf("\nGondoltam egy számra 1 és 100 között, találd ki melyikre! \n"); + scanf(" %d", &number); + trials++; + + while (number != a){ + trials++; + printf("régi szám:%d, új szám:%d", old_number, number); + if (old_number == number) { + trials--; + printf("ezt a számot épp most írtad, figyelj jobban!\n"); + } + if (number < a){ + printf("Nem talált, a szám kisebb, mint a Te tipped. Próbáld újra! \n"); + old_number = number; + scanf(" %d", &number); + } + else { + printf("Nem talált, a szám nagyobb, mint a Te tipped. Próbáld újra! \n"); + old_number = number; + scanf(" %d", &number); + } + + } + printf("Szuper! Eltaláltad! %d-t találgattál.\n", trials); + return 0; +} +//most jó \ No newline at end of file diff --git a/helloworld/hello.c b/helloworld/hello.c index 0d5c11e..ad32754 100644 --- a/helloworld/hello.c +++ b/helloworld/hello.c @@ -1,8 +1,8 @@ #include #include int main() { - char first_name[100];/* define first_name */ - char last_name[100];/* define last_name */ + char first_name[100] = "John";/* define first_name */ + char last_name[100] = "Doe"; /* define last_name */ char name[100]; last_name[0] = 'B'; diff --git a/helloworld/kukutyin.c b/helloworld/kukutyin.c new file mode 100644 index 0000000..5a8df52 --- /dev/null +++ b/helloworld/kukutyin.c @@ -0,0 +1,27 @@ +#include + +int main(){ +//definiáljuk a szükséges változókat + int ellen; + int adossag; + + setbuf(stdout, NULL); + + printf("\nHány ellenség van?"); + scanf("%d", &ellen); + printf("\nHány tallér az adósság?"); + scanf("%d", &adossag); + + if ((ellen == 1 || ellen == 2 ) && adossag > 100){ + + printf("\nSKANDALUM");} + + if (ellen == 0 && adossag > 0) { + + printf("\nIMBECIL"); + } + + + +return 0; +} \ No newline at end of file