[go: up one dir, main page]

0% found this document useful (0 votes)
68 views2 pages

PSCP Assignment-2 Loops

This document contains 10 programming problems involving loops, number properties, and mathematical operations: 1) Write a program to print Dudeney numbers below 10,000. 2) Write a program to find all square-free numbers below 1,000. 3) Write a program to print numbers not in the Fibonacci series up to n. 4) Write a program to encode 5-digit numbers by replacing each digit with the sum of digits modulus 10. 5) Write a program to display the annual population of a town increasing 15% each year until it surpasses 50,000. 6) Write a program to repeatedly sum the digits of a number until a single digit is reached. 7

Uploaded by

Hardik Rangwani
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)
68 views2 pages

PSCP Assignment-2 Loops

This document contains 10 programming problems involving loops, number properties, and mathematical operations: 1) Write a program to print Dudeney numbers below 10,000. 2) Write a program to find all square-free numbers below 1,000. 3) Write a program to print numbers not in the Fibonacci series up to n. 4) Write a program to encode 5-digit numbers by replacing each digit with the sum of digits modulus 10. 5) Write a program to display the annual population of a town increasing 15% each year until it surpasses 50,000. 6) Write a program to repeatedly sum the digits of a number until a single digit is reached. 7

Uploaded by

Hardik Rangwani
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/ 2

PSCP Assignment-2 (Loops) MED A&B

Due date: 17/01/2022


1. A Dudeney number is a positive integer that equals the cube of its sum of digits. For
example, 512 = 8 * 8 * 8 is a Dudeney number because 8 = 5 + 1 + 2. Similarly, 4913 =
17 * 17 * 17 is Dudeney as 17 = 4 + 9 + 1 + 3. Write a program to print the Dudeney
numbers below 10000.

2. A positive integer is called square-free if it is not divisible by the square of any prime
number. For Example, 98 = 2×49, 99 = 9×11, 100 = 4×25 are not square-free, whereas
42=2×3×7 and 102 = 2×3×17 are square-free. Write a program to find all square-free
numbers below 1000.

3. The Fibonacci series 0,1,1,2,3,5,8,13… begins with the terms 0 and 1 and has theproperty
that each succeeding term is the sum of the two preceding terms. Write a program to
print all numbers that do not appear in the Fibonacci series upto the given ‘n’.

4. An organization wants to transmit data securely over telephone, but they are concerned
that their phone may be tapped. All the data are transmitted as five digit numbers. The
organization wants to hide the actual five digit number by encoding so that it can be
transmitted more securely. The encoding method is as follows. Each digit in the number
will be replaced by sum of digits upto that digit modulus 10. Write a program which takes
(as input) a series of five digit numbers and print the encoded numbers.For example, if
the number is 23849, the encoded number is computed ad follows 2%10=2, (2+3)%10=5,
(2+3+8)%10=3,(2+3+8+4)%10=7, (2+3+8+4+9)%10=6, Hence the encoded number is
25376.

5. There are 9000 people in a town whose population increases by 15% each year. Write a
program that displays the annual population and determines the number of years it will
take for the population to surpass 50000.

6. Write a program to accept a number and find sum of its individual digits repeatedly till
the result is a single digit. For example, if the given number is 4687, sum of digits=
4+6+8+7=25=2+5=7. Output should be 7.

7. Write a menu driven program which has following options

1-Factorial of a number
2-Prime or not
3-Odd or even
4. Nth Fibonacci number
5-Exit
Once a menu item is selected the appropriate option should be taken and once this option
is finished, the menu should reappear .Unless the user selects the Exit option the program
should continue work.

8. Write a program to print out all Armstrong numbers between 1 and 500. If sum of cubes
of each digit of the number is equal to the number itself, then the number is called an
Armstrong number. For example 153= (1*1*1) + (5*5*5) + (3*3*3).
9. Sridhar, the man who delivers eggs to my home every day, did not turn up one day. So
when he came the next morning I demanded an explanation from him. He told me the
following story: The previous morning when he just came out of the house carrying a
basketful of eggs on his head to start his daily rounds and stepped on to the street, a car
going at full speed brushed against him and knocked down his basket destroying all the
eggs. The driver, however, a thorough gentleman (Mahesh) admitted his responsibility
and offered to compensate him for damages. But Sridhar could not remember the exact
number of eggs he had, but he estimated the number between 50 to 100. He was also able
to tell Mahesh that if the eggs were counted by 2’s and 3’s at a time, none would be left,
but if counted by 5’s at a time, 3 would remain, and that he sold the eggs 50 paise a piece.
The Mahesh made some quick calculations and paid Sridhar adequately. How much did
the Mahesh pay Sridhar? Write a program for this.

10. If you have two fractions, a/b and c/d, their sum can be obtained from the formula: for
example, 1/4 plus 2/3 is (1/4)+(2/3) = 11/12 Write a program that encourages the user to
enter two fractions and the display their sum in fractional form. The interaction with the
user might look like this:
Enter first fraction: 1 / 2, Enter second fraction: 2 / 5, sum = 9 / 10

You might also like