zad 1. napisac program w C++ ktory losuje liczby od 0 do 500 wyswietla je, sumuje i liczy srednia.
#include <cstdio>#include <stdint.h>#include <cstdlib>int main(){ uint64_t sum = 0; uint16_t rnd;
int count;
scanf("%i", &count); for (int i=0; i<count; i++) { rnd = rand()%500; printf("%i ", rnd); sum += rnd; } printf("\nSum: %llu", sum);
printf("\nAverage: %f", (double)sum/count);}
Przykład działania:
http://ideone.com/D26Ic
" Life is not a problem to be solved but a reality to be experienced! "
© Copyright 2013 - 2024 KUDO.TIPS - All rights reserved.
#include <cstdio>
#include <stdint.h>
#include <cstdlib>
int main()
{
uint64_t sum = 0;
uint16_t rnd;
int count;
scanf("%i", &count);
for (int i=0; i<count; i++)
{
rnd = rand()%500;
printf("%i ", rnd);
sum += rnd;
}
printf("\nSum: %llu", sum);
printf("\nAverage: %f", (double)sum/count);
}
Przykład działania:
http://ideone.com/D26Ic