KEMBAR78
Practice | PDF | Numbers | Arithmetic
0% found this document useful (0 votes)
52 views3 pages

Practice

The document outlines a series of programming tasks that involve basic arithmetic operations, grade conversion, summation, number manipulation, and drawing shapes. Each task specifies input requirements, expected output, and enhancements for additional functionality. The tasks also cover concepts such as arrays, prime number checking, and user interaction through loops.

Uploaded by

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

Practice

The document outlines a series of programming tasks that involve basic arithmetic operations, grade conversion, summation, number manipulation, and drawing shapes. Each task specifies input requirements, expected output, and enhancements for additional functionality. The tasks also cover concepts such as arrays, prime number checking, and user interaction through loops.

Uploaded by

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

1.

Calculating arithmetic operations

Write a program which will allow user to input a valid arithmetic expression
(number operation number) and will print out the result.
E.g. Input 5 + 6 Output "5 + 6 = 11"

Enhance the program to print the result of devision as a floating point number.
E.g. Input 10 / 3 Output "10 / 3 = 3.333"
Enhance the program to use "switch" operator instead of if/else

2. Grades to letters
Write a program that allows the user to enter the grade scored in a class: 0-100.
Notify the user of their letter grade: 0-59 F 60-69 D 70-79 C 80-89 B 90-100 A
E.g. Input 88 - Output "Your grade is B"

Enhance the program to work in "interactive" mode: let the user to continue
requests and receive output, until -1 is not entered.

Requires:
Variables, data types, basic I/O, branching/loops

3. Calculate the sum


Write a program which will input number N in range of [1-1000] and print the sum of
all multiples of 3 and 5 below N.
E.g. If we list all the natural numbers below 10 that are multiples of 3 or 5, we
get 3, 5, 6 and 9. The sum of these multiples is 23.

4. Calculate sum of the digits


Write a program which will input an integer number and will print the sum of the
digits of the number.
E.g. Input 123 - Output 6 (which is 1 + 2 + 3)

Requires:
Variables, data types, basic I/O, branching/loops

5. Inverse the number


Write a program which will input an integer number and calculate the inverse of the
number. Print the output.
E.g. Input 163 - Output 361

6. Prime numbers
Input a number and check if it is a prime number. Print the answer.
6.1 Input number N and print all prime numbers in the range 1-N

7.Palindrome numbers
Input a number and check if it is a palindrome number. Print the answer.
E.g 1789871 is a palindrome

8. Concatenate numbers
Input 2 numbers and concatenate them together
e.g. for 35 and 47 the output number should be 3547

9. Power of 2
Input a number and check if it is a power of 2.

10. Draw rectangle


Write a program which will input two integer - N and M. The program should "draw" a
rectangle of NxM size using "*" and spaces.
E.g. Input 6 4
Output

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

Enhance the program to input the character to be use for "drawing"


E.g. Input 6 4 $

$$$$$$
$ $
$ $
$$$$$$

11. Draw triangle


Write a program which will input an integer number - N, and "draw" two types of
right-angled triangle of height N.
E.g Input 5
Output

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

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

12. Draw triangle-2


Write a program which will input an integer number - N, and "draw" isosceles
triangle with base N.
E.g. input 5

*
***
*****

Enhance the program to print a triangle of height N.

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

13. Guess a number


Write a program that calculates a random number 1 through 100. The program then
asks the user to guess the number. If the user guesses too high or too low then the
program should output "too high" or "too low" accordingly.
The program must let the user continue to guess until the user correctly guesses
the number. Output how many guesses it took the user to correctly guess the right
number.
Tip: use standard library functionality to generate the random number:
http://en.cppreference.com/w/cpp/numeric/random/rand

14. Guess a number (opposite)


Write a program which asks the user to think a of random number from 1 to 100 and
try to guess the number. The user must tell the computer whether the guessed number
is too high or too low.

Modify the program so that no matter what number the user thinks of (1-100) the
computer can guess it in 7 or less guesses.

Arrays

11. Write a program to input 10 numbers and find the minimal and maximal numbers in
the sequence. Print the results.

12. Write a program which will allow user to input numbers in range 1-10 (as much
as the user would like to, till -1 is entered)
Calculate and print how many times each of the numbers have been entered.

13. Write a program to input a number and convert it to binary (e.g in 4 bits)
e.g Input 5 , Output 0101
Enhance the program to support also negative numbers (calculate 2's complement)

14. Write a program to input a binary number (a sequence of 0-1s) and convert it to
decimal. Print the results.

15. Write a program that asks the user to type 10 integers of an array and an
integer value N. The program must search if the value N exists in the array and
must remove the first occurrence of N, shifting each following element left and
adding a zero at the end of the array. The program must then print the final array.

You might also like