school/for.c

28 lines
533 B
C
Raw Normal View History

2023-12-18 15:36:37 +01:00
//
// Created by bruno on 12/18/23.
//
#include "for.h"
#include "stdio.h"
2024-01-22 14:41:15 +01:00
int for_cyklus() {
2023-12-18 15:36:37 +01:00
int target;
2023-12-18 15:46:42 +01:00
2023-12-18 15:36:37 +01:00
printf("Do akého čísla počítať?");
scanf("%d", &target);
2023-12-18 15:46:42 +01:00
printf("Zadal si číslo %d.\n", target);
printf("Cyklus FOR:\n");
2024-01-22 14:41:15 +01:00
for (int i = 0; i <= target; i++) {
if (i % 2 == 1) {
2023-12-18 15:59:29 +01:00
printf("%d\n", i);
}
2023-12-18 15:46:42 +01:00
}
2023-12-18 15:59:29 +01:00
printf("\nCyklus WHILE:\n");
2023-12-18 15:46:42 +01:00
int i = 0;
2024-01-22 14:41:15 +01:00
while (i <= target) {
if (i % 2 == 1) {
2023-12-18 15:59:29 +01:00
printf("%d\n", i);
}
2023-12-18 15:46:42 +01:00
i++;
2023-12-18 15:36:37 +01:00
}
}