0% found this document useful (0 votes)
13 views

NUMBER

Uploaded by

0w0HM
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

NUMBER

Uploaded by

0w0HM
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

NUMBER BASED QUESTIONS

1. Consider the sequence of natural numbers


1, 2, 3, 4, 5, 6, 7……Removing every second number produces the sequence
1, 3, 5, 7, 9, 11, 13, 15, 17, ……….Removing every third number produces the sequence
1, 3, 7, 9, 13, 15, 19, 21, 25, 27, ………This process continues indefinitely by removing
fourth, fifth …. and so on, till after a fixed number of steps certain numbers remains
indefinitely. These are known as lucky numbers. Write a program to generate and print
lucky numbers less then a given natural number N where N<=50.
2. Input consist of month number (MM), the day of the month (DD) and the year (YYYY).
Write a program to calculate and print the corresponding day of the year ( in the range 1
to 366).
Example:
Input: Month 05
Day 03
Year 1996
Output: CORRESPONDING DAY OF THE YEAR IS : 124
( 31 + 29 + 31 + 30 + 3 = 124 )
Test your program with the following sample data.
MONTH DAY YEAR
09 07 2000
05 03 1954
12 13 1960
3. Twin primes are consecutive prime numbers whose difference is 2. For example, (3,5),
(11,13), (17,19) are all twin primes. We define the distance of any twin prime pair from a
positive integer as follows: If (p1,p2) is a twin prime pair and n is a positive integer then
the distance of the twin prime pair from n is: minimum(abs(n-p1), abs(n-p2)) where abs
returns the absolute value of its argument, and minimum returns the smaller of its two
arguments. Write a program that reads in a positive integer n and prints out the twin
prime pair that has the least distance from n.
For example if n is 30 the pair is (29,31), if n is 13 it is (11,13), if n is 49 it is (41,43), if n
is 54 it is (59,61).
Sample data:
Input:
Give the number:34
Output:
Number read in is:34
p1=29 p2=31
Input:
Give the number:60
Output:
Number read in is:60
p1=59 p2=61
4. Give a time in numbers we can convert it into words.
For example5:00 five o’ clock
5:10 ten minutes past five
5:15 QUARTER PAST FIVE
5:30 HALF PAST FIVE
5:40 twenty minutes to six
5:45 quarter to six
5:47 thirteen minutes to six
Write a program which first inputs two integers, the first between 1 and 12 (both
inclusive) and second between 0 and 59 (both inclusive) and then prints out the time they
represent, in words. Your program should follow the format of the examples above.
SAMPLE DATA:
INPUT:
TIME: 3,0
OUTPUT: 3:00 three o’ clock
INPUT:
TIME: 7,29
OUTPUT: 7:29 twenty nine minutes past seven
INPUT:
TIME: 6,34
OUTPUT: 6:34 twenty six minutes to seven
INPUT:
TIME: 12,1
OUTPUT: 12:01 one minute past twelve
INPUT:
TIME: 12,45
OUTPUT: 12:45 quarter to one
INPUT:
TIME: 10,59
OUTPUT: 10:59 one minute to eleven
INPUT:
TIME: 14:60
OUTPUT: incorrect input
Test your program for the data values given in the examples above and some random
data.
5. Numbers have different representations depending on the bases on which they are
expressed. For example in base 3, the number 12 is written as 110 (1×32 + 1×31 + 0x30),
but in base 8 it is written as 14 (1×81 + 4×80).Consider, for example, the integers 12 and
5. Certainly these are not equal if base 10 is used for each. But suppose 12 was a base 3
number and 5 was a base 6 number then what happens, 12 base 3=1×31 + 2×30, or 5 base
6 or 5 base 10(5 in any base is equal to 5 base 10). So 12 and 5 can be equal if you select
the right bases for each of them.Write a program to input two integers, X and Y, and
calculate the smallest base for X and smallest base for Y (likely different from X) so that
X and Y represent the same value. The base associated with X and Y will be between 1
and 20 (both inclusive). In representing these numbers the digits 0 to 0 have their usual
decimal interpretations. The upper case alphabetic characters A through J represent digits
10 through 19 respectively.
Test your program for the following data and some random data:
SAMPLE DATA:
INPUT:
X=12, Y=5
OUTPUT:
12(base 3)=5(base 6)
INPUT:
X=10, Y=A
OUTPUT:
10(base 10)=A(base 11)
INPUT:
X=12, Y=34
OUTPUT:
12(base 17)=34(base 5)
INPUT:
X=123, Y=456
OUTPUT:
1 2 3 is not equal to 456 in any base between 2 to 20
INPUT:
X=42, Y=36
OUTPUT:
42(base 7)=36(base 8).
6. The manager of a company wants to analyse the machine usage from the records to find
the utilization of the machine. He wants to know how long each user used the machine.
When the user wants to use the machine he must login to the machine and after finishing
the work he must log off the machine.
Each log record consists of.
User identification number.
Login time and date.
Time consists of. Hours Minutes
Date consists of. Day MonthYou may assume all logins and logouts are in the same year
and there are 100 users at the most. The time format is 24 hour machine hours and
minutes.Design a program:
(a) To find the duration for which each user has logged. Output all records along with the
duration in hours (format hours: minutes).
(b) Output the record of the user who logged for the longest duration. You may assume
that no user will login for more than 48 hours.
Test your program for the following data values and some more random data.
SAMPLE DATA:
INPUT:
Number of users:3USER LOGIN LOGOUT
IDENTIFICATION TIME & DATE TIME & DATE
149 20:10 20-12 2:50 21-12
173 12:30 20-12 12:30 21-12
142 16:20 20-12 16:30 20-12

OUTPUT:
USER LOGIN LOGOUT DURATION
IDENTIFICATION TIME & DATE TIME & DATE HOURS:MINS
149 20:10 20-12 2:50 21-12 6:40
173 12:30 20-12 12:30 21-12 24:00
142 16:20 20-12 16:30 20-12 00:10THE USER WHO LOGGED IN FOR
THE LONGEST DURATION:
173 12:30 20-12 12:30 21-12 24:00
7. A prime palindrome integer is a positive integer (without leading zeros) which is prime as
well as a palindrome. Given two positive integers m and n, where m<= n, write a
program to determine how many prime-palindrome integers are there in the range
between m and n (both inclusive) and output them.
The input contains two positive integers m and n where m>=100 and n<= 3000.
Display number of prime palindrome integers in the specified range along with their
values in the format specified below:
Test your program with the sample data and some random data:
Example 1:
INPUT:
M=100
N=1000
OUTPUT: The prime palindrome integers are:
101,131,151,181,191,313,351,373,383,727,757,787,797,919,929
Frequency of prime palindrome integers: 15
Example 2:
INPUT:
M=100
N=5000
OUTPUT: Out of Range
8. An ISBN (International Standard Book Number) is a ten digit code which uniquely
identifies a book.
The first nine digits represent the group, publisher and title of the book and the last digit is
used to check whether ISBN is correct or not.
Each of the first nine digits of the code can take a value between 0 to 9. Sometimes it is
necessary to make the last digit equal to ten. This is done by writing the last digit of the code
as X.
To verify an ISBN, calculate 10 times the first digit, plus 9 times the second digit, plus 8
times the third digit and so on until we add 1 time the last digit. If the final number leaves no
remainder while divided by 11, the code is a valid ISBN
For example:
0201103311=10*0+9*2+8*0+7*1+6*1+5*0+4*3+3*3+2*1+1*1=55
This is a valid ISBN
007462542X=10*0+9*0+8*7+7*4+6*6+5*2+4*5+3*4+2*2+1*10=176
This is a valid ISBN
Similarly 0112112425 is not a valid ISBN.
Test Data:
Input code: 0201530821
Output: Sum=99
Leaves no remainder – valid ISBN
Input code: 356680324
Output: Sum=invalid input
Input code: 0231428031
Output: Sum=122
Leaves remainder – invalid ISBN
9. Write a program to input two valid dates, each comprising of day (2 digit) month (2 digit)
and year (4 digit) and calculate the day elapsed between the two dates.
Test your program with following data values:
Example:
First date: Day: 24
Month : 09
Year : 1960
Second Date: Day: 10
Month: 12
Year: 1852First date: Day: 10
Month : 01
Year : 1952
Second Date: Day: 16
Month: 10
Year: 1952
10. A Circular Prime is a prime number that remains prime under cyclic shifts of its digits.
When the leftmost digit is removed and replaced at the end of the remaining string of
digits, the generated number is still prime. The process is repeated until the original
number is reached again.

A number is said to be prime if it has only two factors 1 and itself.

Example:
131
311
113
Hence, 131 is a circular prime.

Accept a positive number N and check whether it is a circular prime or not. The new
numbers formed after the shifting of the digits should also be displayed.

Test your program with the following data and some random data:

Example 1

INPUT:
N = 197

OUTPUT:
197
971
719
197 IS A CIRCULAR PRIME.

Example 2

INPUT:
N = 1193

OUTPUT:
1193
1931
9311
3119
1193 IS A CIRCULAR PRIME.

Example 3

INPUT:
N = 29

OUTPUT:
29
92
29 IS NOT A CIRCULAR PRIME.

*********************************

You might also like