Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8ca0a27
finalization
Goodwitch68 Oct 12, 2019
ebe0fdf
final version
Goodwitch68 Oct 12, 2019
0610b58
final version
Goodwitch68 Oct 12, 2019
29c851b
az elemetary 4 és 5 feladat kész
Goodwitch68 Oct 12, 2019
a950431
change indentation
Goodwitch68 Oct 12, 2019
f22c8ef
Committing everything before reinstalling Acer.
Goodwitch68 Oct 13, 2019
a7fb8c2
ez volt a megabyte megoldása ugyanerre a kérdésre
Goodwitch68 Oct 16, 2019
726d085
jól dönti el, hogy prim-e, de nem jól ír ki
Goodwitch68 Oct 16, 2019
97147f0
itt nem ír már ki semmit, pedig csak egy if-et tettem bele
Goodwitch68 Oct 16, 2019
5f65aef
Elementary_7 working, before adding is_prime().
Goodwitch68 Oct 16, 2019
1859aeb
Elementary_6 working with bug in printf
Goodwitch68 Oct 17, 2019
f235aa4
Elementary_8 working
Goodwitch68 Oct 17, 2019
febeedf
Elementary_6 properly working ver
Goodwitch68 Oct 17, 2019
dce717a
Elementary_9 working, without eliminating of consecutiv repeatition
Goodwitch68 Oct 19, 2019
8b35926
elementary_9 proper working
Goodwitch68 Oct 19, 2019
c5a2e5f
elementary_9 better
Goodwitch68 Oct 19, 2019
5d747d0
elementary_10 proper working
Goodwitch68 Oct 19, 2019
b2c70df
Interesting problem to discuss
Goodwitch68 Oct 19, 2019
98cd6a5
Elementary-11 proper working
Goodwitch68 Oct 19, 2019
b4911af
Elementary_6 done, committed earlier
Goodwitch68 Oct 22, 2019
f335068
Elementary_7 done, committed earlier
Goodwitch68 Oct 22, 2019
c73e876
Elementary_8 done, committed earlier
Goodwitch68 Oct 22, 2019
d2d9c4b
Elementary_2_3 Bob == Bob return 0, why?
Goodwitch68 Oct 25, 2019
b6cb2f0
elementary_2_3.c intended proper way
Goodwitch68 Oct 25, 2019
4c30325
elementary_4.c intended proper way
Goodwitch68 Oct 25, 2019
f222325
elementary_4_5.c intended proper way
Goodwitch68 Oct 25, 2019
03ef10d
elementary_6 intended proper way
Goodwitch68 Oct 25, 2019
d0cfd51
elementary_7 intended proper way
Goodwitch68 Oct 25, 2019
e561815
elementary_8 intended proper way
Goodwitch68 Oct 25, 2019
9a1d9b1
elementary_9 intended proper way
Goodwitch68 Oct 25, 2019
95a5c87
elementary_10 intended proper way
Goodwitch68 Oct 25, 2019
1404159
elementary_11 intended proper way
Goodwitch68 Oct 25, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions helloworld/elementary_10.c
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;
Copy link
Copy Markdown
Collaborator

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:

time_t s = time(NULL);
time_t val = 1;

struct tm* current_time;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

struct tm* current_time = localtime(&s);


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;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ félrevezető változónév: a next_leap_year alapján arra gondol az ember, hogy ez a következő szökőév évszáma. Én valami olyan nevet adnék neki, hogy years_until_next_leap_year

int leap_year = current_year + next_leap_year;

for (int i = 0; i < 20; i++){
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A kapcsos zárójel előtt legyen szóköz:
for (int i = 0; i < 20; i++) {

if (leap_year % 100 == 0){
i--;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nem értem, hogy ennek mi a célja
Ja, hogy az i-nek csak akkor szabad növekednie, amikor tényleg leap year van, hogy meg tudd számolni, mikor jutsz a 20-ig, értem.

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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vagy
} else { (a jelen program stílusát ez követné)
vagy

}
else
{

(ha a többi kapcsos zárójelet is új sorba kezded)
de semmiképp nem

}

ezen kívül pedig a printf()-es sort még eggyel beljebb indentáld
else {

}
return 0;
}

//2920-ig használható, később tévesen kihagyja a 3000-et
39 changes: 39 additions & 0 deletions helloworld/elementary_10_fura.c
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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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("Day of the month = %d\n", current_time->tm_mday);

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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Az tényleg apróság, de én így írnám:

    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;
}*/
Comment on lines +22 to +34
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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;
}

22 changes: 22 additions & 0 deletions helloworld/elementary_11.c
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++){
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hiányzik pár space (a <= és a { előtt)

sum = sum + (pow (-1, k)/(2*k-1));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a pow() egy függvény, nem kell utána space.

Az egész sor így néz ki elegánsan:
sum = sum + (pow(-1, k) / (2 * k - 1));
Az operátorok köré kell space.

printf("\nSum*4 is 1-%f-ig: %f", k, sum*4);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Általában a sor végére szokás tenni a \n-t. Indokolt esetben lehet az elején, de itt nem látom, hogy az lenne.

}
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.
22 changes: 22 additions & 0 deletions helloworld/elementary_2_3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include<stdio.h>

int main() {

char name [100]; /* define name */
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a name után nem kell space.


setbuf(stdout, NULL);

printf("Hogy hívnak? ");
scanf("%s", &name);

if ( name == "Alice" || name == "Bob") {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A name elé nem kell space.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arról, hogy miért nem működik a ==-val történő hasonlítás majd beszéljük.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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;
}
18 changes: 18 additions & 0 deletions helloworld/elementary_4.c
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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

	int szam = 0;
	int osszeg = 0;

Í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 scanf("%d", &szam); mondhatjuk azt, hogy használod, mert a scanf() lehetne egy olyan függvény is, ami nem írni akar a szam változóba, hanem olvasni belőle a pointeren keresztül.


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 :-)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

legközelebb osszeg = (1 + szam)*szam / 2;

setbuf(stdout, NULL);
printf("A számok összege 1-%d-ig:%d", szam, osszeg);


return 0;
}
24 changes: 24 additions & 0 deletions helloworld/elementary_4_5.c
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
35 changes: 35 additions & 0 deletions helloworld/elementary_6.c
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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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 scanf() sort? Az azért is lenne jobb, mert később ha átnevezed a dontes változót, akkor elég egy helyen átírni, és nem fordulhat elő, hogy az egyik helyen átírtad, de a másikon elfelejtetted.

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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

} else if (dontes == 'p') {
vagy simán
} else {
hiszen ha nem 's' a dontes, akkor csak 'p' lehet

for (int i = 1; i <= szam; i++) {
szorzat = szorzat * i;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

szorzat *= i

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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
40 changes: 40 additions & 0 deletions helloworld/elementary_7.c
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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ez már kész van?


return 0;
}
24 changes: 24 additions & 0 deletions helloworld/elementary_8.c
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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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
42 changes: 42 additions & 0 deletions helloworld/elementary_9.c
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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

	srand(time(NULL));
	int a = rand() % 100 + 1;

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++;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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){
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space a { előtt

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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

} 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ó
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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)

4 changes: 2 additions & 2 deletions helloworld/hello.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <stdio.h>
#include <string.h>
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';
Expand Down
27 changes: 27 additions & 0 deletions helloworld/kukutyin.c
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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ez nem erre a branch-re való