Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include<math.h>
- double binarne(int n, double licz[]);
- int main()
- {
- double wy=0;
- double tab[5] = {0, 0, 1,1, 1};
- wy = binarne(4, tab);
- printf("liczba to: %f", wy);
- getchar();
- return 0;
- }
- double binarne(int n, double licz[])
- {
- double wynik =0;
- double k=0;
- double suma=0;
- double tak=1.0;
- double nie=0;
- for(n; n>=0; n--)
- {
- if(licz[n] == tak)
- {
- wynik = pow(2,k);
- suma+=wynik;
- }
- if(licz[0] == nie){
- }
- else
- {
- printf("Liczba binarna to tylko zera i jedynki! Blad!");
- }
- k++;
- }
- return suma;
- }
Add Comment
Please, Sign In to add comment