Question 1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Question 1-Count digits

Take the following as input.


A number
A digit
Write a code that returns the number of times digit is found in the number. Print the
value returned.

Input Format

Integer (A number) Integer (A digit)

Constraints

0 <= N <= 1000000000 0 <= Digit <= 9

Output Format

Integer (count of times digit occurs in the number)

Sample Input
5433231
3

Sample Output
3

Explanation

The digit can be from 0 to 9. Assume decimal numbers.In

the given case digit 3 is occurring 3 times in the given

number.
Question 2- Print the reverse
Take N as input, Calculate it's reverse also Print the reverse.

Input Format

Constraints

0 <= N <= 1000000000

Output Format

Sample Input
123456789

Sample Output
987654321

Explanation

You've to calculate the reverse in a number, not just print

the reverse.

Question 3--Replace them all


Given a integer as a input and replace all the '0' with '5' in the integer
Input Format

Enter an integer n

Constraints

0<=n<=1000000000000

Output Format

All zeroes are replaced with 5

Sample Input
102

Sample Output
152

Explanation

Check each digit , if it is nonzero, then no change required

but if it is zero then replace it by 5.

Question 4--Fibonacci

Take N as input. Print Nth Fibonacci Number, given that the first two numbers in the
Fibonacci Series are 0 and 1.

Input Format

Constraints
0 <= N <= 1000

Output Format

Sample Input
10

Sample Output
55

Explanation

The 0th fibonnaci is 0 and 1st fibonnaci is 1.

Question 5-Sum of odd and even


placed digits.
Take N as input. Print the sum of its odd placed digits and sum of its even placed
digits.

Input Format

Constraints

0 < N <= 1000000000

Output Format
Sample Input
2635

Sample Output
11
5

Explanation

5 is present at 1st position, 3 is present at 2nd position, 6

is present at 3rd position and 2 is present at 4th position.

Sum of odd placed digits on first line. 5 and 6 are placed

at odd position. Hence odd place sum is 5+6=11

Sum of even placed digits on second line. 3 and 2 are

placed at even position. Hence even place sum is 3+2=5

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy