CodeQuotient Solutions
CodeQuotient Solutions
Q2 Decimal to Binary(C++)
void decimalToBinary(int n)
{
//Write your Code here
int binaryNum[32];
Q3 Fibonacci sequence
nterms = int(input())
#print the first nterms of the Fibonacci sequence
def recur_fibo(n):
if n <= 1:
return n
else:
return(recur_fibo(n-1) + recur_fibo(n-2))
def addDigitByDigit(a,b,c):
# Write your code here
sum = 0
for digit in str(a,b,c):
sum += int(digit)
return sum
Q5 Pyramid - 6
# Type your code here
row = int(input())
for i in range(1,row+1):
for j in range(i,0,-1):
print(j, end='')
for j in range(2,i+1):
print(j, end='')
print()
def factorial(n):
if n == 0:
return 1
return n * factorial(n-1)
t = int(input().strip())
for _ in range(t):
n = int(input())
print(sumDigits(n))
Q8 Reverse a number
# Type your code here
rev = 0
n = int(input().strip())
while(n > 0):
a = n % 10
rev = rev * 10 + a
n = n // 10
print(rev)
Q9 Fibonacci sequence using recursion
# Type your code here
def fibo(n, a, b):
if (n > 0):
fibo(n - 1, b, a + b)
print(a, end="\n")
n = int(input().strip())
fibo(n,0,1)
while (i < j )
{
while (arr[i] <=x && i < j )
i++;
while (arr[j] > x && i < j )
j--;
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
i++;
j--;
}
}