User Tools

Site Tools


dydaktyka:cprog:2015:revision_1-solutions

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
dydaktyka:cprog:2015:revision_1-solutions [2015/11/08 19:34]
pkleczek utworzono
— (current)
Line 1: Line 1:
-====== Zadania powtórkowe (1) - rozwiązania ====== 
- 
-===== Zadanie 1 ===== 
- 
-<code c> 
-#include <​stdio.h>​ 
-#include <​stdlib.h>​ 
- 
- int ile_pierwiastkow(int a, int b, int c) { 
-    int delta = b * b - 4 * a * c; 
- 
-    if (delta < 0) { 
-        return 0; 
-    } else if (delta == 0) { 
-        return 1; 
-    } else { 
-        return 2; 
-    } 
- } 
- 
-int main() 
-{ 
-    double a, b, c; 
- 
-    printf("​Podaj wspolczynniki a, b i c: "); 
-    scanf("​%lf %lf %lf", &a, &b, &c); 
- 
-    printf("​Ilosc pierwiastkow:​ %d\n", ile_pierwiastkow(a,​ b, c)); 
- 
-    return 0; 
-} 
-</​code>​ 
- 
-===== Zadanie 2 ===== 
- 
-<code c> 
-#include <​stdio.h>​ 
-#include <​stdlib.h>​ 
- 
- int czy_kwadrat(int n) { 
-     int i; 
- 
-     for (i = 1; i < n; i = i + 1) { 
-        if (i*i == n) { 
-            return 1; 
-        } 
-     } 
- 
-     ​return 0; 
-} 
- 
-int main() 
-{ 
-    int n; 
- 
-    n = 4; 
-    printf("​Czy %d jest kwadratem pewnej liczby? - %d\n", n, czy_kwadrat(n));​ 
- 
-    n = 5; 
-    printf("​Czy %d jest kwadratem pewnej liczby? - %d\n", n, czy_kwadrat(n));​ 
- 
-    return 0; 
-} 
-</​code>​ 
- 
-===== Zadanie 3 ===== 
- 
-<code c> 
-#include <​stdio.h>​ 
-#include <​stdlib.h>​ 
- 
- int wieksza(int a, int b) { 
-     if (a > b) { 
-        return a; 
-     } 
-     ​return b; 
-} 
- 
-int main() 
-{ 
-    int p = 4; 
-    int q = 7; 
- 
-    printf("​Liczba wieksza z %d i %d to: %d\n", p, q, wieksza(p, q)); 
- 
-    return 0; 
-} 
-</​code>​ 
- 
-===== Zadanie 4 ===== 
- 
-<code c> 
-#include <​stdio.h>​ 
-#include <​stdlib.h>​ 
- 
- ​double srednia(double a, double b, double c) { 
-     ​return (a + b + c) / 3; 
-} 
- 
-int main() 
-{ 
-    double p = 2; 
-    double q = 4; 
-    double r = 9; 
- 
-    printf("​Srednia z %f, %f i %f wynosi %f\n", p, q, r, srednia(p, q, r)); 
- 
-    return 0; 
-} 
-</​code>​ 
- 
-===== Zadanie 5 ===== 
- 
-<code c> 
-#include <​stdio.h>​ 
-#include <​stdlib.h>​ 
- 
-double oblicz(double x) 
-{ 
-    return (x * x * x  + 3 * x) / (x * x + 6); 
-} 
- 
-int main() 
-{ 
-    double x = 2.0; 
- 
-    printf("​y(%f) = %f\n", x, oblicz(x)); 
- 
-    return 0; 
-} 
-</​code>​ 
- 
  
dydaktyka/cprog/2015/revision_1-solutions.1447007669.txt.gz · Last modified: 2020/03/25 11:46 (external edit)