Professional Documents
Culture Documents
Semester
COMP 150 (Introduction to Programming)
CRN#: 50890
Assignment# 3
Submitted to:
Prof. Siddhartha Shyam Vyas
Submitted by:
Name: Simranpreet Kaur (300200432)
BCIS, Year 1
Signature:
(i)
ACKNOWLEDGEMENT
I would like to express my special thanks to Prof. Siddhartha Shyam Vyas, Ph.D. thank you to
give me the golden opportunity to do this assignment 1. Your valuable guidance has been the
one that helped me to patch this assignment and make it full proof of success. Your suggestions
and instructions have served as a major contributor to the completion of the assignment.
I have achieved a good amount of knowledge through the assignment.
Simranpreet Kaur
Signature:
(ii)
1. WAP using user-defined function - 'find_max ()'
Take two user inputs in the main () function. Make sure that the two numbers
entered by the user aren't equal
'Find_max ()' must find the maximum of two numbers using the 'if-else' statement.
'Find_max ()' must return the maximum of two numbers to the main () function for
printing the maximum value.
ANS.
1
2. WAP to perform a four-function calculator using 'nested if-else / 'switch-case'.
Create a different user-defined function for the following:
Take the user input in the main () function.
addition () - for calculating addition two numbers
difference () - for calculating the difference between two numbers
product () - for calculating the product of two numbers
division () - for calculating the division of two numbers.
All these user-defined functions must return a value to the main () function for
printing the result.
ANS.
2
3
3. WAP to create a user-defined function 'factorial ()'
Take a user input in the main () function.
factorial () must compute the factorial of a given number
factorial () must return a value to the main () function for printing the result.
ANS.
4
4. WAP to create a user-defined function - 'Sum_of_natural_numbers ()'
Take a user limit in main () function
'Sum_of_natural_numbers ()' must compute the sum of natural numbers
'Sum_of_natural_numbers ()' must return a value to the main () function for
printing the result
ANS.
5
5. WAP to create two user defined functions - 'Sum_of_even numbers ()' and
'sum_of_odd_numbers ()'
Take the range limit in the main () function
'Sum_of_even_numbers ()' must compute the sum of even numbers
'Sum_of_odd_numbers ()' must compute the sum of odd numbers
Both the user-defined functions must return the values to the main () function for
printing the result
ANS.
6
7
6. WAP to sum up two numbers using functions
* Take two integer values as user input in the main ()
* The sum () must compute the addition of two numbers
* The sum () must return an integer value, that is, the result of addition to main ()
for printing the result
ANS.
8
7. WAP to create a user-defined function - print days ()
Take an integer value as user input in the range of 1-7 in main ()
print days () must print the days as per the values entered by the user
If the user enters 1 -----> "It is Monday" must be printed in a new line
If the user enters 2 -----> "It is Tuesday" must be printed in a new line and so on
and on until the user enters 7.
print days () must not return a value to main ()
Hint: You may use 'switch-case' or 'nested if-else as per your convenience
ANS.
9
8. WAP to compute the sum of digits using functions
* Take integer value as user input in the main ()
* The sum_of_digits () must compute the sum of digits of the user input taken on
the run time screen
* The sum_of_digits () must return an integer value to main () for printing the
result
ANS.
10
9. WAP to find whether the given number is an Armstrong number or not using
functions
* Take integer value as user input in the main ()
* Armstrong () must check whether the user input is an Armstrong number or not
* Armstrong () must return an integer value to main () for printing whether the
given number is an Armstrong number.
ANS.
11
12
10. WAP to check whether the given number is a palindrome number or not using
functions
* Take an integer value as user input in the main ()
* Palindrome () must check whether the given number is a palindrome or not
* Palindrome () must return an integer value to the main () for printing whether
the given number is palindrome or not
ANS.
13