Guest User

Untitled

a guest
Jun 24th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.90 KB | None | 0 0
  1. #include <stdio.h>
  2. #include<math.h>
  3.  
  4. double binarne(int n, double licz[]);
  5.  
  6. int main()
  7. {
  8.        
  9.  
  10.        
  11.        double wy=0;
  12.        
  13.        double tab[5] = {0, 0, 1,1, 1};
  14.        wy = binarne(4, tab);
  15.            
  16.        printf("liczba to: %f", wy);
  17.  
  18.        getchar();
  19.        return 0;
  20. }
  21.  
  22. double binarne(int n, double licz[])
  23. {
  24.        double wynik =0;
  25.        double k=0;
  26.        double suma=0;
  27.        double tak=1.0;
  28.        double nie=0;
  29.  
  30.        for(n; n>=0; n--)
  31.        {
  32.  
  33.               if(licz[n] == tak)
  34.               {
  35.                      wynik = pow(2,k);
  36.                      suma+=wynik;
  37.               }
  38.               if(licz[0] == nie){
  39.              
  40.               }
  41.               else
  42.               {
  43.  
  44.               printf("Liczba binarna to tylko zera i jedynki! Blad!");
  45.               }
  46.  
  47.               k++;
  48.              
  49.        }
  50.        return suma;
  51.  
  52.        
  53. }
Add Comment
Please, Sign In to add comment