ACCENTURE TECHNICAL CODING
1. A carry is a digit that is transferred to left if sum of digits exceeds 9 while adding two numbers from
right-to-left one digit at a time
You are required to implement the following function, Int NumberOfCarries(int num1 , int num2);
The functions accepts two numbers ‘num1’ and ‘num2’ as its arguments. You are required to calculate
and return the total number of carries generated while adding digits of two numbers ‘num1’ and ‘
num2’.
Assumption: num1, num2>=0
Example:
Input
• Num 1: 451
• Num 2: 349
Output
•2
Explanation:
Adding ‘num 1’ and ‘num 2’ right-to-left results in 2 carries since ( 1+9) is 10. 1 is carried and
(5+4=1) is 10, again 1 is carried. Hence 2 is returned.
Sample Input
Num 1: 23
Num 2: 563
Sample Output
0
2. N-base notation is a system for writing numbers which uses only n different symbols, This symbols
are the first n symbols from the given notation list(Including the symbol for o) Decimal to n base
notation are (0:0, 1:1, 2:2, 3:3, 4:4, 5:5, 6:6, 7:7, 8:8, 9:9, 10:A,11:B and so on upto 35:Z)
Implement the following function, Char* DectoNBase(int n, int num):
The function accept positive integer n and num Implement the function to calculate the n-base
equivalent of num and return the same as a string
Steps:
• Divide the decimal number by n,Treat the division as the integer division
• Write the the remainder (in n-base notation)
• Divide the quotient again by n, Treat the division as integer division
• Repeat step 2 and 3 until the quotient is 0
• The n-base value is the sequence of the remainders from last to first
Assumption:
1 < n < = 36
Example
Input
n: 12
Page 1 of 5
, ACCENTURE TECHNICAL CODING
num: 718
Output
4BA
Explanation
num Divisor quotient remainder
718 12 59 10(A)
59 12 4 11(B)
4 12 0 4(4)
Sample Input
n: 21
num: 5678
Sample Output
CI8
3. The function def differenceofSum(n. m) accepts two integers n, m as arguments Find the sum of all
numbers in range from 1 to m(both inclusive) that are not divisible by n. Return difference between
sum of integers not divisible by n with sum of numbers divisible by n.
Assumption:
● n>0 and m>0
● Sum lies between integral range
Example
Input
n:4
m:20
Output
90
Explanation
● Sum of numbers divisible by 4 are 4 + 8 + 12 + 16 + 20 = 60
● Sum of numbers not divisible by 4 are 1 +2 + 3 + 5 + 6 + 7 + 9 + 10 + 11 + 13 + 14 + 15 + 17 + 18
+ 19 = 150
● Difference 150 – 60 = 90
Sample Input
n:3
m:10
Sample Output
19
4. You are required to implement the following Function def LargeSmallSum(arr).
The function accepts an integers arr of size ’length’ as its arguments you are required to return the
sum of second largest largest element from the even positions and second smallest from the odd
position of given ‘arr’.
Page 2 of 5
1. A carry is a digit that is transferred to left if sum of digits exceeds 9 while adding two numbers from
right-to-left one digit at a time
You are required to implement the following function, Int NumberOfCarries(int num1 , int num2);
The functions accepts two numbers ‘num1’ and ‘num2’ as its arguments. You are required to calculate
and return the total number of carries generated while adding digits of two numbers ‘num1’ and ‘
num2’.
Assumption: num1, num2>=0
Example:
Input
• Num 1: 451
• Num 2: 349
Output
•2
Explanation:
Adding ‘num 1’ and ‘num 2’ right-to-left results in 2 carries since ( 1+9) is 10. 1 is carried and
(5+4=1) is 10, again 1 is carried. Hence 2 is returned.
Sample Input
Num 1: 23
Num 2: 563
Sample Output
0
2. N-base notation is a system for writing numbers which uses only n different symbols, This symbols
are the first n symbols from the given notation list(Including the symbol for o) Decimal to n base
notation are (0:0, 1:1, 2:2, 3:3, 4:4, 5:5, 6:6, 7:7, 8:8, 9:9, 10:A,11:B and so on upto 35:Z)
Implement the following function, Char* DectoNBase(int n, int num):
The function accept positive integer n and num Implement the function to calculate the n-base
equivalent of num and return the same as a string
Steps:
• Divide the decimal number by n,Treat the division as the integer division
• Write the the remainder (in n-base notation)
• Divide the quotient again by n, Treat the division as integer division
• Repeat step 2 and 3 until the quotient is 0
• The n-base value is the sequence of the remainders from last to first
Assumption:
1 < n < = 36
Example
Input
n: 12
Page 1 of 5
, ACCENTURE TECHNICAL CODING
num: 718
Output
4BA
Explanation
num Divisor quotient remainder
718 12 59 10(A)
59 12 4 11(B)
4 12 0 4(4)
Sample Input
n: 21
num: 5678
Sample Output
CI8
3. The function def differenceofSum(n. m) accepts two integers n, m as arguments Find the sum of all
numbers in range from 1 to m(both inclusive) that are not divisible by n. Return difference between
sum of integers not divisible by n with sum of numbers divisible by n.
Assumption:
● n>0 and m>0
● Sum lies between integral range
Example
Input
n:4
m:20
Output
90
Explanation
● Sum of numbers divisible by 4 are 4 + 8 + 12 + 16 + 20 = 60
● Sum of numbers not divisible by 4 are 1 +2 + 3 + 5 + 6 + 7 + 9 + 10 + 11 + 13 + 14 + 15 + 17 + 18
+ 19 = 150
● Difference 150 – 60 = 90
Sample Input
n:3
m:10
Sample Output
19
4. You are required to implement the following Function def LargeSmallSum(arr).
The function accepts an integers arr of size ’length’ as its arguments you are required to return the
sum of second largest largest element from the even positions and second smallest from the odd
position of given ‘arr’.
Page 2 of 5