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, uspjeh;
- uspjeh = scanf("%lf", &broj);
- if(uspjeh == 0) return '\n';
- return broj;
- }
- double Prosjek (long long 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;
- do {
- printf("Unesite cijeli broj: ");
- x = Unesi();
- if(x == '\n' || x != (long long int)x) {
- Ocisti();
- printf("Unos pogresan!\n");
- }
- } while(x == '\n' || x != (long long int)x);
- if(x == 0) {
- printf("Prosjek je: %g", x);
- return 0;
- }
- d = Prosjek(x);
- printf("Prosjek je: %g", d);
- return 0;
- }
Add Comment
Please, Sign In to add comment