Assignment Set01-CSE1101
Assignment Set01-CSE1101
Problem Set 01
Please write your solutions in A4/Letter size paper and provide the handwritten or printed
hardcopy in the department. Aim for concise solutions; convoluted and obtuse descriptions might
receive low marks, even when they are correct.
This assignment is meant to be an evaluation of your individual understanding coming into the
course and should be completed without collaboration or outside help
(Answer any 100 points; At least 20 points from each section. Each question
contributes 10 points)
Section 1. [110 points] Questions - answers
(a) What are the major components of a C program? What significance is attached to the
name main?
(b) Summarize the meaning of each of the following program characteristics: integrity,
clarity, simplicity, efficiency, modularity and generality. Why is each of these
characteristics important?
(c) Summarize the rules for naming identifiers. In your answer, specify the following :
What is the purpose of identifiers? Are uppercase letters equivalent to lowercase letters?
Can digits be included in an identifier name? Can any special characters be included?
How many characters can be included in an identifier name? Are all of these characters
equally significant?
(d) Determine which of the following valid identifiers are. If invalid, explain why.
record1 _ 123- 45 – 6789 _name return
lrecord name-and-address name and address file-3 $tax
(e) In what general category do the #define and #include statements fall? What are the
differences between a symbolic constant and constant define with const keyword.
(f) What is the purpose of the do - while statement? How does it differ from the while
statement? What is the minimum number of times that a do - while loop can be executed?
Compare with a while loop and explain the reasons for the differences.
(g) Can you discuss the trade-offs between using an interpreted language versus a compiled
language for a project? What factors would you consider when making this decision?
(h) What is the purpose of the switch statement? How does this statement differ from if else
other statements? Compare the use of the switch statement with the use of nested if- else
statements. Which is more convenient?
(i) What is the purpose of the break statement? Within which control statements can the
break statement be included? Suppose a break statement is included within the innermost
of several nested control statements. What happens when the break statement is
executed?
(j) What is the purpose of the continue statement? Within which control statements can the
continue statement be included? Compare with the break statement.
(k) Define entry control and exit control loop with their syntax. Discuss their similarity and
dissimilarity.
Rubric:
• -2 point for each wrong answer
• 5 points for correct answer
• 3 points for explanation
• Partial credit may be awarded if there is work shown of a correct approach that does not yield
the correct solution.
(b) In any n credit theory course of BAUST you have to attend in n CTs and of them best n-1
CTs will be counted. Now write a program that shows the average of best n-1 CTs marks out
of n CTs.
Sample input:
Enter the value of n: 4
i. 1st CT Marks: 15
ii. 2nd CT Marks: 10
iii. 3rd CT Marks: 15
iv. 4th CT Marks: 15
Sample Output:
Average of best 3 CT marks: 15
(c) We know, there is a rule for valid triangle and there are various types of triangles in terms of
their angle and sides’ length. Now observe some of the following triangle shapes.
i. Present a C program to check whether a triangle is valid or not if sides are given.
ii. Compile a C program to check whether a triangle is equilateral, scalene or
isosceles.
(d) Write a program in C that will ask the user to enter the total shopping amount purchased in
the shop and then apply the discount as per the following discount criteria, then find and print
the final amount that has to be paid by the customer after subtracting the discount amount:
If the user has purchased something that costs from $101 to $200, the discount will be
5%.
If the user has purchased something that costs from $201 to $400, the discount will be
10%.
If the user has purchased something that costs from $401 to $800, the discount will be
20%.
And if the user has purchased something that costs more than $800, the total discount
that will be applied to the whole purchase amount is 25%.
(e) Consider the following scenarios, you are given two baskets, one basket is labelled as 18
number and another one is labelled as 29 number. In label 18 basket, there is a ball which is
labelled as number 29, and in another basket, label 18 number ball is present. Now, your task
is to keep those two balls in those two baskets so that the baskets and balls label number
match.
(f) Write a program that takes a character as input and prints out one of the following sentences
as appropriate:
• Vowel in capital letter
• Vowel in small letter
• Consonant in capital letter
• Consonant in small letter
• Neither a vowel nor a consonant
(g) Write an appropriate control structure that will examine the value of a floating-point variable
called temp and print one of the following messages, depending on the value assigned to
temp. (a) ICE, if the value of temp is less than 0. (b) WATER, if the value of temp lies
between 0and 100. (c) STEAM, if the value of temp exceeds 100. Can a switch statement be
used in this instance?
(h) Write a switch statement that will examine the value of a char-type variable called color and
print one of the following messages, depending on the character assigned to color. (a) RED,
if either r or R is assigned to color, (b) GREEN, if either g or G is assigned to color, (c)
BLUE, if either b or B is assigned to color, (d) BLACK, if color is assigned any other
character.
(i) A prime number is a whole number greater than 1 whose only factors are 1 and itself. A factor is
a whole number that can be divided evenly into another number. The first few prime numbers are
2, 3, 5, 7, 11, 13, 17, 19, 23 and 29. Numbers that have more than two factors are called
composite numbers. Now, write a C Program that will print all the prime number up to a positive
integer n.
(j) An Armstrong number is one whose sum of digits raised to the power three equals the number
itself. 371, for example, is an Armstrong number because 3**3 + 7**3 + 1**3 = 371. Now, write
a C Program to Display Armstrong Number between Two Intervals.
(k) The Fibonacci sequence is a sequence where the next term is the sum of the previous two terms.
The first two terms of the Fibonacci sequence are 0 followed by 1. Now, write a C Program to
display the Fibonacci sequence of first n numbers where n is a positive integer less than 100.
(l) A palindromic number (also known as a numeral palindrome or a numeric palindrome) is a
number (such as 16461) that remains the same when its digits are reversed. In other words, it has
relational symmetry across a vertical axis. Now, write a C program to check whether a number is
palindrome or not.
(m) Leap years are years where an extra day is added to the end of the shortest month, February.
This so-called intercalary day, February 29, is commonly referred to as leap day.Leap years have
366 days instead of the usual 365 days and occur almost every four years.
[
A leap year is exactly divisible by 4 except for century years (years ending with 00). The century
year is a leap year only if it is perfectly divisible by 400.For example,
Now, write a C Program to check whether the year entered by the user is a leap year or not.
Section 3. [60 points] Print Pyramids and Patterns: Write C Program to display the
following Pyramids or Patterns
* 1 *********
*** 232 *******
***** 34543 *****
******* 4567654 ***
********* 567898765 *
a) Stars Pyramid b) Numbers Pyramid c) Inverted Stars
Pyramid
1 1 1
1 1 23 23
1 2 1 456 456
1 3 3 1 7 8 9 10 7 8 9 10
1 4 6 4 1 11 12 13 14 15 11 12 13 14 15
1 5 10 10 5 1 16 17 18 19 20 21 16 17 18 19 20 21
d) Pascal's Triangle e) Floyd's Triangle f) Floyd's Pyramid
Rubric:
• Parts (a)-(j)
- 1 points for indentation
- 1 points for documentation
- 1 points for coherence
- 2points for logical integrity
- 5 points for correct code
- Partial credit may be awarded
• Part (k)
- 5 points for each correct pyramid or pattern
- Partial credit may be awarded
Section 3. [60 points] Describe the output that will be generated by each of the following C
programs. (Note the similarities in the programs that are shown across from each other.)
(c) (d)
(e) (f)
Rubric:
• -1 point for each wrong answer
• 5 points for correct answer
• 5 points for description
• Partial credit may be awarded if there is work shown of a correct approach that does not yield
the correct solution.