-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/adriann elementary #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
8ca0a27
ebe0fdf
0610b58
29c851b
a950431
f22c8ef
a7fb8c2
726d085
97147f0
5f65aef
1859aeb
f235aa4
febeedf
dce717a
8b35926
c5a2e5f
5d747d0
b2c70df
98cd6a5
b4911af
f335068
c73e876
d2d9c4b
b6cb2f0
4c30325
f222325
03ef10d
d0cfd51
e561815
9a1d9b1
95a5c87
1404159
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #include <stdio.h> | ||
| #include <time.h> | ||
| int main() { | ||
|
|
||
| time_t s, val = 1; | ||
| struct tm* current_time; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| 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; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ félrevezető változónév: a |
||
| int leap_year = current_year + next_leap_year; | ||
|
|
||
| for (int i = 0; i < 20; i++){ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A kapcsos zárójel előtt legyen szóköz: |
||
| if (leap_year % 100 == 0){ | ||
| i--; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Viszont innentől kezdve a for loop kicsit nehezen átlátható, Majd beszéljük meg. |
||
| } | ||
| else { | ||
| printf("%d, ", leap_year); | ||
| } | ||
| leap_year = leap_year + 4; | ||
|
Comment on lines
+19
to
+23
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. vagy (ha a többi kapcsos zárójelet is új sorba kezded) |
||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| //2920-ig használható, később tévesen kihagyja a 3000-et | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #include <stdio.h> | ||
| #include <time.h> | ||
| int main() | ||
| { | ||
| time_t s, val = 1; | ||
| struct tm* current_time; | ||
|
|
||
| s = time(NULL); | ||
|
|
||
| current_time = localtime(&s); | ||
|
Comment on lines
+5
to
+10
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ld. fent |
||
|
|
||
| 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)); | ||
|
Comment on lines
+12
to
+16
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a vessző után tegyél szóközt a függvény paraméterei között, pl: |
||
| printf("hour:min:sec = %02d:%02d:%02d\n", | ||
| current_time->tm_hour, | ||
| current_time->tm_min, | ||
| current_time->tm_sec); | ||
|
Comment on lines
+17
to
+20
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Az tényleg apróság, de én így írnám: |
||
|
|
||
| /* 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; | ||
| }*/ | ||
|
Comment on lines
+22
to
+34
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kikommentelt kódot, ami nem oda való, és már sose lesz rá szükség, nem jó szokás benn hagyni. Ha később mégis kell, elő lehet túrni git-ből. |
||
|
|
||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 <stdio.h> | ||
| #include <math.h> | ||
|
|
||
| int main(){ | ||
|
|
||
| double sum = 0; | ||
| for (double k = 1; k<= 1000000; k++){ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hiányzik pár space (a |
||
| sum = sum + (pow (-1, k)/(2*k-1)); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a Az egész sor így néz ki elegánsan: |
||
| printf("\nSum*4 is 1-%f-ig: %f", k, sum*4); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Általában a sor végére szokás tenni a |
||
| } | ||
| 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. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #include<stdio.h> | ||
|
|
||
| int main() { | ||
|
|
||
| char name [100]; /* define name */ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a |
||
|
|
||
| setbuf(stdout, NULL); | ||
|
|
||
| printf("Hogy hívnak? "); | ||
| scanf("%s", &name); | ||
|
|
||
| if ( name == "Alice" || name == "Bob") { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Arról, hogy miért nem működik a
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Egyébként nem azt mondtad, hogy ezt egyszer már megoldottad hogy csak Alice-el és Bob-bal működjön, csak "továbbfejlesztetted", hogy megmutasd, hogy kezdőbetűk szerint is tudod? |
||
|
|
||
| setbuf(stdout, NULL); | ||
| printf("Üdvözöllek, %s!", name); | ||
| } | ||
|
|
||
| printf("%s!", name); | ||
| printf ("%d\n", name == "Bob"); | ||
|
|
||
| return 0; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| #include<stdio.h> | ||
|
|
||
| int main() { | ||
|
|
||
| int szam; | ||
| int osszeg; | ||
|
Comment on lines
+5
to
+6
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Így kiszámíthatőbb a működés, ha később változtatsz a programon, plusz nem szabad inicializálatlan változót használni, márpedig a |
||
|
|
||
| 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 :-) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 Ez felvet egy izgalmas témát az algoritmusokról, amivel még találkozni fogsz. Van az ún. "big O notation", ami azt fejezi ki, hogy egy algoritmus által igénybevett idő miként függ a bemenetek számától, méretétől, stb. Ha kétszer annyi elemmel valami kétszer annyi idejig is tart, magyarán az idő n-nel egyenesen arányok, akkor az algoritmusra azt mondják, hogy O(n) komplexitású. Ha a szükséges idő négyzetesen nő a bemenettel, akkor az O(n²). Ha úgy nő, mint a faktoriális, akkor O(n!). Itt ha ciklust használtál volna, akkor O(n) komplexitású algoritmust írtál volna, mert minél nagyobb számot ír be az ember, annál többször kell lefutnia a ciklusnak. Ez a megoldás viszont O(1) komplexitású, aminek örülünk, mert ugyanolyan gyors bármely számra.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. legközelebb |
||
| setbuf(stdout, NULL); | ||
| printf("A számok összege 1-%d-ig:%d", szam, osszeg); | ||
|
|
||
|
|
||
| return 0; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| #include<stdio.h> | ||
|
|
||
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #include<stdio.h> | ||
|
|
||
| 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); | ||
| } | ||
|
Comment on lines
+15
to
+22
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. milyen loop-pal lehetne ezt jobban megcsinálni, hogy ne kelljen kétszer megírni a |
||
| if (dontes == 's') { | ||
| osszeg = (1 + szam)*szam/2; | ||
| printf("A számok összege 1-%d-ig:%d\n", szam, osszeg); | ||
| } | ||
| if (dontes == 'p') { | ||
|
Comment on lines
+26
to
+27
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| for (int i = 1; i <= szam; i++) { | ||
| szorzat = szorzat * i; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Esetleg érdemes lehet itt csekkolni, hogy nincs-e integer overflow. |
||
| } | ||
| printf("A számok produktuma 1-%d-ig:%d\n", szam, szorzat); | ||
| } | ||
| return 0; | ||
| } | ||
| //most jól fut | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| #include<stdio.h> | ||
| #include<math.h> | ||
|
|
||
| // 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 | ||
| } | ||
| } | ||
|
Comment on lines
+24
to
+37
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ez már kész van? |
||
|
|
||
| return 0; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| #include<stdio.h> | ||
|
|
||
|
|
||
| // ez tképpen a 7-es feladat, csak benéztem a számot | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Akkor nevezd át a fájlokat? |
||
|
|
||
| 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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| #include<stdio.h> | ||
| #include <stdlib.h> | ||
|
|
||
| int main(int argc, char *argv[]) | ||
| { | ||
| int a; | ||
| srand(time(NULL)); | ||
| a = rand() % 100 + 1; | ||
|
Comment on lines
+6
to
+8
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kerüljük az érték nélküli változó létrehozást, ha lehet. |
||
|
|
||
| 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++; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ez miért kell? |
||
|
|
||
| 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){ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space 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 { | ||
|
Comment on lines
+31
to
+32
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| 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ó | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ezt ne ide írd, hanem a commit message-be (fájlnévvel együtt) |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #include<stdio.h> | ||
|
|
||
| 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; | ||
| } | ||
|
Comment on lines
+1
to
+27
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ez nem erre a branch-re való |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ezeket külön sorban deklaráld, az olvashatóbb.
Az is kicsit fura, hogy az egyiknek egyből adsz értéket, a másiknak meg csak két sorral lejebb.
Én így csinálnám: