You are on page 1of 2

ASSIGNMENT NO.

5
ITC (Arrays)
Submission: (on portal.ucp.edu.pk) Due Date: 17-janury-2021 by 11:59 PM
No late submission allowed
NOTE: These problems should be attempted individually. If there are confusions or questions,
see your Lab Instructors or Course Instructor. Attempting the problems individually is important for a
thorough understanding of the course material and also for successfully attempting the exams. You
need to upload .cpp files on portal.

Part I: All Problems Should Be Done Using Arrays Only

Question 1:
Write a C++ program that reads 10 numbers from the user, stores them into an array, and then print
largest, smallest number, sum of all the numbers on the screen, sum of those numbers that are less than
20, the sum of odd and even number, count of numbers that are prime and print the count of numbers
that are perfect squares.
Example:
If the User enters 11, 2, 15, 34, 18, 2, 15, 18, 15, 50 then program should print:
Largest = 50
Smallest = 2
SUM = 180
Sum of number less than 20 = 96
Sum of even numbers =
Sum of odd numbers =
There are 2 prime number
There are 4 perfect squares

Question 2:
Write a C++ program that first reads a number (a single integer number having 5 digits) from the user. It
should then separate its digits and stores each digit in an array. Finally, it should check whether the
number is in base 3 or not. Any number of base 3 must have all digits less than 3 (you will check whether
each index of the array has a value less than 3 stored in it or not)

Example 1: If the user enters 45678 then program should print that 45678 is not in base 3
Example 2: If the User enters 21021 then program should print that 21021 is in base 3
Question 3:
Write a C++ program that keeps on getting numbers from the user in an array. The maximum size of the
array is 100. The user keeps on entering the values till -9999 is entered. The program then prints the
count, sum and average of all the entered numbers

Example: If the user entered 6 12 9 234 623 -9999 then the program should print Count = 5, Sum = 884
and Average = 176.8

Question 4:
Write a C++ program that reads an integer number from the user as an input. It should then separate
the digits and stores each in an array. The user can enter up to 8 digits. The program prints a new
number on the using the following rule:

Numbers with odd number of digits is rotated about the middle number and even numbers are rotated
about the 2 middle digits.

In order to understand this question, see the example below. The numbers having the same color are
swapped to produce the rotated new number.:

Example 1: User Entered 12345 then program should print 54321

Example 2: User Entered 123456 then program should print 653421

Question 5:
Write a C++ program that gets a number (integer) from the user as an input. It should then separate the
digits and stores each digit in an array. The user can enter up to 8 digits. The program should then print
the middle digit (odd number of digits) or middle 2 digits (even number of digits)

Example 1: User Entered 12345 then program should print Middle Digit is 3
Example 2: User Entered 123456 then program should print Middle Digits are 3 & 4

You might also like