Please test the correctness of your program in 2) and 3) using PASS.
- Write a program which define and initialize an array of 10 integers:
int num[10]={5,10,2,5,8, 8, 7,9, 1,5};
Using the elements in the array, print a bar chart with lengths equal to corresponding element in the array:
*****
**********
**
*****
********
********
*******
*********
*
*****
Hint: You should use nested-for loops.
The outer-for repeatedly retrieve the value a[i] where 0<=i<10 and the inner-for loop is used to print * n times, followed by endl
- Write a program which read two sets of integer elements (10 elements for each set) and find the intersection of two entered sets. (According to the definition of set, elements are guaranteed to be unique within set)
Expected Output:
Example-1 | Example-2 |
Enter 10 Elements of Set A: 1 2 3 4 5 6 7 8 9 10Enter 10 Elements of Set B:11 12 13 14 15 16 17 18 19 20 The Intersected Element of Set A and B are not Found. | Enter 10 Elements of Set A: 1 2 3 4 5 6 7 8 9 10Enter 10 Elements of Set B:1 2 3 4 5 6 7 8 9 10The Intersected Elements of Set A and B are:1 2 3 4 5 6 7 8 9 10 |
Example-3 | Example-4 |
Enter 10 Elements of Set A: 1 2 3 4 5 6 7 8 9 10Enter 10 Elements of Set B:1 3 5 7 9 11 13 15 17 19The Intersected Elements of Set A and B are: 1 3 5 7 9 | Enter 10 Elements of Set A:-1 -2 -3 -4 -5 -6 -7 -8 -9 -10Enter 10 Elements of Set B:-1 -3 -5 -7 -9 -11 -13 -15 -17 -19The Intersected Elements of Set A and B are:-1 -3 -5 -7 -9 |
Computer Programming
- Write a program which read the first name of a person as an array of characters:
char Name[100]; cin >> Name;
Derive whether name is palindrome or not.
l A palindrome is a word or any sequence of characters which reads the same backward or forward.
l Entered words should be case sensitive. (i.e. A and a are considered different)
l You can use the strlen() function to find the length of a string
(by #include <string.h>). For example, if the entered name is CityU then strlen(Name) will return 5.
Expected Output:
Example-1 | Example-2 |
Enter the First Name: madam madam is palindrome | Enter the First Name:MadamMadam is not palindrome |
Example-3 | Example-4 |
Enter the First Name:ANNAANNA is palindrome | Enter the First Name: mark mark is not palindrome |
Reviews
There are no reviews yet.