Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void Ocisti () {
- char x = 'a';
- while(x != '\n')
- scanf("%c", &x);
- }
- double Unesi () {
- double broj;
- scanf("%lf", &broj);
- return broj;
- }
- double Prosjek (int broj) {
- int brojac = 0, suma = 0, c;
- double prosjek;
- while(broj != 0) {
- c = broj % 10;
- brojac++;
- suma += c;
- broj /= 10;
- }
- prosjek = (double)suma / brojac;
- return prosjek;
- }
- int main() {
- double x, d;
- int cijeli;
- do {
- printf("Unesite cijeli broj: ");
- x = Unesi();
- if(x != (int)x) {
- Ocisti();
- printf("Unos pogresan!\n");
- }
- } while(x != (int)x);
- cijeli = x;
- if(cijeli == 0) {
- printf("Prosjek je: %d", cijeli);
- return 0;
- }
- d = Prosjek(cijeli);
- printf("Prosjek je: %g", d);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement