Iterative Construct
Section B
2005
Question 8
Write a program to print the sum of negative numbers, sum of positive even numbers and sum of positive odd numbers from a list of numbers (N) entered by the User. The list terminates when the User enters a zero [15]
Variable Description
Variable | Type | Description |
---|---|---|
num | int | For number |
n | int | For number of numbers |
s1, s2, s3 | int | For sum of negative, positive even, and positive odd |
i | int | Loop variable |
2006
Question 8
Write a program to calculate and print the sum of odd numbers and the sum of even numbers
for the first n natural numbers. The integer n is to be entered by the user. [15]
2008
Question 7
Write a menu driven class to accept a number from the user and check whether it is Palindrome or Perfect.
(a) Palindrome number - (a number is a Palindrome when read in reverse order is same as read in the right order)
Example: 11,101,151.
(b) Perfect number - (a number is called Perfect if it is equal to the sum of its factors other than the number itself.)
Example: 6=1+2+3
[15]
Question 9
Write a program to calculate and print the sum of each of the following series: [15]
(a) Sum (S) = 2 – 4 + 6 – 8 + … - 20
(b) Sum (S) =x/2 + x/5 + x/8+ x/11 + ….+ x/20
(Value of x to be input by the user.)
2009
Question 5
Write a program to generate a triangle or an inverted triangle till n terms based upon the user’s choice:[15]
Example 1
Input:
Type 1 for a triangle and
type 2 for an inverted triangle
1
Enter the number of terms : 5
Output :
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
Example 2
Input:
Type 1 for a triangle and
type 2 for an inverted triangle
2
Enter the number of terms: 6
Output :
6 6 6 6 6 6
5 5 5 5 5
4 4 4 4
3 3 3
2 2
1
Question 8
Write a menu driven program to accept a number from the user and check whether it is a ‘BUZZ’ number or to accept any two numbers and print the ‘GCD’ of them.
(a) A BUZZ number is number which either ends with 7 or divisible by 7.
(b) GCD (Greatest Common Divisor) of two integers is calculated by continued division method.
Divide the larger number by the smaller; the remainder then divides the previous divisor.
This process is repeated till the remainder is zero. The divisor then results the GCD. [15]
2010
Question 6 Question 7 Question 6 Question 9 Question 8 Question 5 Question 9 Question 5 Question 9 Question 5 Question 5 Question 6 Question 5 Question 5 Question 9 Question 8
Shasha Travels Pvt. Ltd. gives the following discount to its customers:
Ticket amount Discount
Above Rs. 70000 18%
Rs. 55001 to Rs. 70000 16%
Rs. 35001 to Rs. 55000 12
Less than Rs. 25001 2
Write a program to input the name and ticket amount for the customer and calculate the discount amount and net amount to be paid. Display the output in the following format for each customer.
(Imagine there are 15 customers, first customer is given the serial number 1, next customer 2. so on) [15]
Sl.No.NameTicket chargesDiscountNet amount
1--------
Write a menu driven program to accept a number and check and display whether it is prime number or not OR an automorphic number or not. (Use switch case statement.)
(a) Prime number: A number is said to be prime number if it is divisible only by 1 and itself and not by any other number. E.g.: 3,5,7,11,13, etc.
(b) Automorphic number: An automorphic number is the number which is contained in the last digit(s)of its square. E.g.: 25 is an automorphic number as its square is 625 and 25 is present as last two digits.
[15] 2011
Write a program to input a number and print whether it is a special number or not. (A number is said to be a special number if the sum of the factorial of the digits of the number same as the number). Example: 145.
1! + 4! + 5! = 1 + 24 +120 = 145. (Where ! stands for factorial and factorial of a number is product of integers from 1 to that number. Example 5! = 1*2*3*4*5=120) [[15]]
Write a menu driven program to perform the following: Use switch case.
(a) To print series 0, 3, 8, 15, 24 … n terms (value of n is to be input by user).
(b) To find the sum of the series: S=1/2 + 3/4 + 5/6 + … + 19/20
[15] 2012
Using the switch statement write a menu driven program to:
(i) Generate and display the first 10 terms of the Fibonacci series 0, 1, 1, 2, 3, 5 …
The first two Fibonacci numbers are 0 and 1, and each subsequent number is the sum of the previous two.
(ii) Find the sum of the digits of an integer that is input.
Sample input: 15390 Sample output: Sum of digits=18
For an incorrect choice an appropriate error message should be displayed.
[15] 2013
The International Standard Book Number (ISBN) is a unique numeric book identifier which is printed on every book. The ISBN is based upon 10 digit code.
The ISBN is legal if: 1*digit1 + 2*digit2 + 3*digit3 + 4*digit4 + 5*digit5 + 6*digit6 + 7*digit7 + 8*digit8 + 9*digit9 + 10*digit10 is divisible by 11.
Example: for an ISBN 1401601499
Sum = 1*1 + 2*4 + 3*0 + 4*1 + 5*6 + 6*0 + 7*1 + 8*4 + 9*9 + 10*9 = 253 which is divisible by 11.
Write a program to:
(i) Input the ISBN code as a 10 digit integer.
(ii) If the ISBN is not a 10 digit number, output the message, “Illegal ISBN” and terminate the program.
(iii) If the number is 10 digit, extract the digits of the number and compute the sum as explained above
If the sum is divisible by 11, output a message, “Legal ISBN”. If the sum is not divisible by 11, output the, “Illegal ISBN”.
[15]
Using the switch statement, write a menu driven program:
(i) To check and display whether a number input by the user is a composite number or not. (A number is said to be a composite, if it has one or more than one factor excluding 1 and the number itself.
Example : 4,6,8,9…).
(ii) To find the smallest digit of an integer that is input.
Sample input: 6524
Sample output: smallest digit is 2
For an incorrect choice, an appropriate error message should be displayed.
[15] 2015
Write two separate programs to generate the following patterns using iteration (loop) statements:
a)
*
* #
* # *
* # * #
* # * # *
b)
5 4 3 2 1
5 4 3 2
5 4 3
5 4
5 [[15]]
Using a switch statement write a menu driven program to:
(i) To find and display all the factors of a number input by the user (including 1 and excluding the number itself.
Sample input: n=15
Sample output: 1, 3, 5
(ii) To find and display the factorial of a number input by the user (the factorial of a non-negative integer n, denoted by n!, is the product of all integer less than or equal to n.
Sample input: n=5
Sample output: 5! = 1x2x3x4x5 = 120
For an incorrect choice an appropriate error message should be displayed.
[15] 2016
Using the switch statement, write a menu driven program for the following:
(i) To print the Floyd’s triangle given below
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
(ii) To display the following pattern:
I
I C
I C S
I C S E
For an incorrect option, an appropriate error message should be displayed.
[15] 2017
Write a program to accept a number and check and display whether it is a spy number or not.
(A number is spy if the sum of its digits equals the product of its digits.)
Example: Consider the number 1124. Sum of digits:= 1+1+2+4=8. Product of digits = 1*1*2*4 = 8 [[15]]
Using switch statement, write a menu driven program for the following:
(i) To find and display the sum of the series given below:
S=x1 - x2 + x3 - x4 + x5 ……. - x20 (where x=2)
(ii) To display the following series:
1 11 111 1111 11111
For an incorrect option an appropriate error message should be displayed
[15] 2018
Write a program to input a number and check and print whether it is a Pronic number or not. (Pronic number is the number which is the product of two consecutive integers)
Examples: 12=3x4, 20=4x5, 41=6x7 [[15]]2019
Using switch statement write a menu driven program to do the following:
(a) To generate and print Letters from A to Z and their Unicode
LettersUnicode
A 65
B 66
.. ..
Z 90
(b) Display the following pattern using iteration statement:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
[15]
A tech number has even number of digits. If the number is split in two equal halves, then square of sum of these halves is equal to the number itself. Write a program to generate and print all four digits tech numbers.
Example: Consider the number 3025
Square of sum of the halves of 3025 = (30+25)2 = (55)2 = 3025 is a tech number. [[15]]2020
Write a menu driven program to perform the following operations as per user’s choice: [15]
(i) To print the value of c=a2+2ab, where a varies from 1.0 to 20.0 with increment of 2.0 and b=3.0 is a constant.
(ii) To display the following pattern using for loop:
A
AB
ABC
ABCD
ABCDE
Display proper message for an invalid choice.