You are on page 1of 18

Summer-2022

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

Due Date of Submission:


09 July, 2022
Date of Submission:
09 July,2022
TABLE OF CONTENTS

S. No. CONTENTS Page


Number
1 CERTIFICATE OF ORIGINALITY i
2 ACKNOWLEDGEMENT ii
3 WAP using user defined function - 'find_max ()' 1
Take two user inputs in the main () function. Make sure that the two
numbers entered by the user aren't equal
To 'find_max ()' and 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.
4 WAP to perform a four-function calculator using 'nested if-else / 2-3
'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
5 WAP to create a user-defined function 'factorial ()' 4
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
6 WAP to create a user-defined function - 'Sum_of_natural_numbers ()' 5
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
7 WAP to create two user defined functions - 'Sum_of_even numbers ()' 6-7
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
8 . WAP to sum up two numbers using functions 8
* 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

9 WAP to create a user-defined function - print days () 9


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
10 WAP to compute the sum of digits using functions 10
* 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
11 WAP to find whether the given number is an Armstrong number or 11-12
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.
12 WAP to check whether the given number is a palindrome number or 13
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
CERTIFICATE OF ORIGINALITY

I hereby declare that:


• I have used my own words
• I have not copied
• I have not plagiarized
• I have cited all the sources from where I have
adapted/sourced.

Name: Simranpreet Kaur (300200432)

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

Name: Simranpreet Kaur (300200432)

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

You might also like