This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
dydaktyka:cprog:2016:functions-solutions [2016/10/29 09:59] pkleczek |
— (current) | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Funkcje - rozwiązania i odpowiedzi ====== | ||
- | |||
- | Laboratorium: [[dydaktyka:cprog:2016:functions]] | ||
- | |||
- | ===== Zadanie GREET ===== | ||
- | |||
- | <code c greet.c> | ||
- | #include <stdio.h> | ||
- | #include <stdlib.h> | ||
- | |||
- | void greet(int n) { | ||
- | int i; | ||
- | |||
- | for (i = 1; i <= n; i = i + 1) { | ||
- | printf("Dzien dobry!\n"); | ||
- | } | ||
- | } | ||
- | |||
- | int main() | ||
- | { | ||
- | greet(3); | ||
- | |||
- | return 0; | ||
- | } | ||
- | </code> | ||
- | |||
- | |||
- | ===== Zadanie LOGOP-1 ===== | ||
- | |||
- | <code c logop-1.c> | ||
- | #include <stdio.h> | ||
- | |||
- | int main() | ||
- | { | ||
- | double a, b, c; | ||
- | |||
- | printf("Podaj trzy liczby: "); | ||
- | scanf("%lf %lf %lf", &a, &b, &c); | ||
- | |||
- | if (a > 0 && b > 0 && c > 0) { | ||
- | printf("Trzy dodatnie!\n"); | ||
- | } else if ((a > 0 && b > 0 && c <= 0) || (a > 0 && b <= 0 && c > 0) || (a <= 0 && b > 0 && c > 0)) { | ||
- | printf("Dwie dodatnie!\n"); | ||
- | } else { | ||
- | printf("Nic :(\n"); | ||
- | } | ||
- | |||
- | return 0; | ||
- | } | ||
- | </code> | ||