aed1oN

ZSR7Z1

Dec 2nd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.80 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void Ocisti () {
  4.     char x = 'a';
  5.     while(x != '\n')
  6.         scanf("%c", &x);
  7. }
  8.  
  9. double Unesi () {
  10.     double broj, uspjeh;
  11.     uspjeh = scanf("%lf", &broj);
  12.     if(uspjeh == 0) return '\n';
  13.     return broj;
  14. }
  15.  
  16. double Prosjek (long long int broj) {
  17.     int brojac = 0, suma = 0, c;
  18.     double prosjek;
  19.     while(broj != 0) {
  20.          c = broj % 10;
  21.          brojac++;
  22.          suma += c;
  23.          broj /= 10;
  24.     }
  25.     prosjek = (double)suma / brojac;
  26.     return prosjek;
  27. }
  28.  
  29. int main() {
  30.     double x, d;
  31.     do {
  32.         printf("Unesite cijeli broj: ");
  33.         x = Unesi();
  34.         if(x == '\n' || x != (long long int)x)  {
  35.             Ocisti();
  36.             printf("Unos pogresan!\n");
  37.         }
  38.     } while(x == '\n' || x != (long long int)x);
  39.     if(x == 0) {
  40.         printf("Prosjek je: %g", x);
  41.         return 0;
  42.     }
  43.     d = Prosjek(x);
  44.     printf("Prosjek je: %g", d);
  45.     return 0;
  46. }
Add Comment
Please, Sign In to add comment