Advertisement
sellmmaahh

OR-Rjesenja Nekih Zadataka-zad2

Aug 28th, 2015
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int Obrni (int n) {
  5.     int nb=0, k=0;
  6.     while (n!=0) {
  7.             nb=nb*10+n%10;
  8.            n/=10;
  9.     }
  10.     return nb;
  11. }
  12.  
  13. int DrugaCifra (int n) {
  14.     int broj=Obrni(n);
  15.     int cifra=0, i=0;
  16.     while (broj!=0) {
  17.             cifra=broj%10;
  18.            i++;
  19.            broj/=10;
  20.            if (i==2 && cifra==5) return 1;
  21.     }
  22.     return 0;
  23. }
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31. int Suma (int*niz, int vel) {
  32.     int i;
  33.      int  suma=0;
  34.      for (i=0; i<vel; i++) {
  35.        if (DrugaCifra(niz[i])) suma+=niz[i];
  36.      }
  37.      return suma;
  38. }
  39.  
  40.  
  41. int main () {
  42.     int niz[6]={25, 53, 5, 185, 357, 2501};
  43.     printf("%d", Suma(niz,6));
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement