Warning
This page is located in archive. Go to the latest version of this course pages. Go the latest version of this page.

2 - Standardní vstup a výstup

Výpočet přepony pravoúhlého trojúhelníka

#include <stdio.h>
#include <math.h>
 
int main()
{
    int a, b;
    float c;
 
    scanf("%i%i", &a, &b);
 
    c = sqrt(a*a + b*b);
 
    printf("Odvesna je %.2f\n", c);
 
    return 0;
}

Rozklad reálného čísla na celou a desetinnou část

#include <stdio.h>
 
int main()
{
    float a;
 
    scanf("%f", &a);
 
    printf("Cela cast: %i\n", (int)a);
    printf("Desetinna cast: %.4f\n", a - (int)a);
 
    return 0;
}

Ořez reálného čísla

#include <stdio.h>
#include <math.h>
 
int main()
{
    float a, c;
    int b;
 
    scanf("%f%i", &a, &b);
 
    c = pow(10,b);
 
    a = (int)(a*c)/c;
 
    printf("Orez na %i desetinna mista: %.*f\n", b, b, a);
 
    return 0;
}

courses/b0b99prpa/solutions/lab02.txt · Last modified: 2020/10/06 08:58 by viteks