tanszek:oktatas:szamitastechnika:ciklusok
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| tanszek:oktatas:szamitastechnika:ciklusok [2025/10/01 12:40] – [Gyakorlás] szabom | tanszek:oktatas:szamitastechnika:ciklusok [2025/10/01 12:42] (current) – [Gyakorlás] szabom | ||
|---|---|---|---|
| Line 138: | Line 138: | ||
| <sxh c> | <sxh c> | ||
| + | #include < | ||
| + | int main(void) { | ||
| + | int N, sum = 0; | ||
| + | scanf(" | ||
| + | |||
| + | for (int i = 1; i <= N; i++) { | ||
| + | sum += i; | ||
| + | } | ||
| + | |||
| + | printf(" | ||
| + | return 0; | ||
| + | } | ||
| </ | </ | ||
| Line 144: | Line 156: | ||
| <sxh c> | <sxh c> | ||
| + | #include < | ||
| + | int main(void) { | ||
| + | int x, sum = 0; | ||
| + | scanf(" | ||
| + | |||
| + | while (x > 0) { | ||
| + | sum += x % 10; // utolsó számjegy | ||
| + | x /= 10; // levágjuk a számjegyet | ||
| + | } | ||
| + | |||
| + | printf(" | ||
| + | return 0; | ||
| + | } | ||
| </ | </ | ||
| Line 150: | Line 175: | ||
| <sxh c> | <sxh c> | ||
| + | #include < | ||
| + | int main(void) { | ||
| + | int tipp; | ||
| + | int titkos = 7; | ||
| + | |||
| + | do { | ||
| + | printf(" | ||
| + | scanf(" | ||
| + | |||
| + | if (tipp < titkos) { | ||
| + | printf(" | ||
| + | } else if (tipp > titkos) { | ||
| + | printf(" | ||
| + | } | ||
| + | } while (tipp != titkos); | ||
| + | |||
| + | printf(" | ||
| + | return 0; | ||
| + | } | ||
| </ | </ | ||
| Line 156: | Line 200: | ||
| <sxh c> | <sxh c> | ||
| + | #include < | ||
| + | int main(void) { | ||
| + | int N; | ||
| + | scanf(" | ||
| + | |||
| + | for (int i = 1; i <= N; i++) { | ||
| + | if (i % 2 != 0) continue; | ||
| + | printf(" | ||
| + | } | ||
| + | printf(" | ||
| + | return 0; | ||
| + | } | ||
| </ | </ | ||
| - | 5. Olvass be egy N számot, és számold ki az N! értékét (pl. 5! = 120) for ciklussal. | + | 5. Olvass be egy N számot, és számold ki az N! értékét (pl. 5! = 120) for ciklussal. |
| <sxh c> | <sxh c> | ||
| + | #include < | ||
| + | int main(void) { | ||
| + | int N; | ||
| + | long long fakt = 1; // nagyobb számokra is jó legyen | ||
| + | |||
| + | scanf(" | ||
| + | |||
| + | for (int i = 1; i <= N; i++) { | ||
| + | fakt *= i; | ||
| + | } | ||
| + | |||
| + | printf(" | ||
| + | return 0; | ||
| + | } | ||
| </ | </ | ||
| - | 6. Olvass be eg N számot, és írd ki a Fibonacci sorozat N elemét for ciklussal. | + | 6. Olvass be eg N számot, és írd ki a Fibonacci sorozat N elemét for ciklussal. |
| <sxh c> | <sxh c> | ||
| + | #include < | ||
| + | |||
| + | int main(void) { | ||
| + | int N; | ||
| + | scanf(" | ||
| + | |||
| + | int a = 0, b = 1; | ||
| + | |||
| + | printf(" | ||
| + | for (int i = 0; i < N; i++) { | ||
| + | printf(" | ||
| + | int kov = a + b; | ||
| + | a = b; | ||
| + | b = kov; | ||
| + | } | ||
| + | printf(" | ||
| + | return 0; | ||
| + | } | ||
| </ | </ | ||
tanszek/oktatas/szamitastechnika/ciklusok.1759322444.txt.gz · Last modified: 2025/10/01 12:40 by szabom
