Advertisement
sellmmaahh

OR-skripta Adijata-zad 48-struktura GRAD

Aug 26th, 2015
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.75 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct Grad
  5. {
  6.  char naziv[20];
  7.  int br_stanovnika;
  8. };
  9.  
  10. int length (char *s) {
  11.     int duz=0;
  12.     while (*(s++)!='\0') duz++;
  13.     return duz;
  14. }
  15.  
  16. int ImaLiA (char *s) {
  17.     int i;
  18.     for (i=0; i<length(s); i++) {
  19.             if (s[i]=='A' || s[i]=='a') return 1;
  20.     }
  21.     return 0;
  22. }
  23.  
  24. int GradoviSaA (struct Grad *niz, int vel) {
  25.     int brojac=0;
  26.     int i;
  27.     for (i=0; i<vel; i++) {
  28.             if (ImaLiA(niz[i].naziv)) brojac+=niz[i].br_stanovnika;
  29.     }
  30.     return brojac;
  31. }
  32.  
  33. int main () {
  34.     struct Grad niz[4]={{"Amterdam",20},{"Olovo",444},{"Mostar",10},{"Visoko",3444}};
  35.     printf("Broj stanovnika gradova koji imaju A(ili a) u imenu: %d",GradoviSaA(niz,4));
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement