Skip to content

Commit 8e992e9

Browse files
committed
change
1 parent 9274f67 commit 8e992e9

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

problem2/Readme.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Problem 02: Binary to Decimal
2+
3+
Write program that convert binary to decimal value
4+
Input : 101010
5+
Output : the equivalent in decimal is : 42
6+
Problem 03: intersection
7+
Given two arrays a1 & a2 , you've to return their intersectoins Example :
8+
a1=[-9,1,2,3,4,0,-2] , a2=[2,8,-1,4]a3=[2,4] or a3=[4,2]

problem2/problem2.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <stdio.h>
2+
#include <math.h>
3+
4+
int main() {
5+
int a[] = {1, 0, 1, 0, 1, 0};
6+
int value = 0;
7+
int cpt = 0;
8+
9+
for (int i = sizeof(a) / sizeof(a[0]) - 1; i >= 0; i--) {
10+
if (a[i] == 1) {
11+
value += pow(2, cpt);
12+
}
13+
cpt++;
14+
}
15+
16+
printf("%d\n", value);
17+
18+
return 0;
19+
}

0 commit comments

Comments
 (0)