Sei sulla pagina 1di 2

Programming Fundamentals

Assignment # 04
Please read the following instructions carefully before submitting the assignment.

It should be clear that your assignment will not get any credit if the assignment is copied (partial or full)
from any source (websites, forums, students etc.). Moreover, no assignment will be accepted after due
date.

Assignment Submission

Deadline: 13 Dec, 2019


Submission Format: In Soft form (.docx file)

Questions
1. Write a program that takes a number from user and pass it to a function. That
function should return the square of the number.
2. Write a program that takes a number from user and pass it to a function. That
function should return the cube of the number.
3. Write a program that inputs two number from user and pass it to a function. That
function should return the power of number as first number raised to power
second number.
4. Write a program that implements the functionality of Question 1, 2 and 3 in a
single program. The program should take a choice from user for a particular
operation (e.g. square, cube or power). Then call respective function to get the
result.
5. Write a program that performs the addition of minimum 2 numbers and
maximum 10 numbers. The program should have a user-defined function for this
purpose. That function will accept max 10 numbers and min 2 numbers in
parameter and then return their sum. For example if I pass 2 parameters to this
function, it should return sum of two digits. If I pass 7 digits, it should return sum
of 7 digits and vice versa.
Hint: Use Default Parameters
6. Implement the above program from Question 5 for subtraction of 2 to 10
numbers.
7. Implement the above program from Question 5 for multiplication of 2 to 10
numbers.
8. Write a program that implements the functionality of programs asked in Question
5, 6 and 7 in a single program. The program should take a choice from user for a
particular operation (e.g. Addition, Subtraction or Multiplication). Then call
respective function to get the result.
9. Write a program that takes two numbers from user and pass them to a function.
That function should swap their values. If I print those numbers in main function
after calling the SWAP function, their swapped values should be displayed.
10. Write a program inputs 10 elements in a 1D array. Pass this array to a function
that should return the max and min value in the array.
11. Write a program that takes 20 elements in a 1D array. Pass this array to a
function. That function should print the no of 1s and 0s in that array.
12. Write a program that takes 10 elements in a 1D array and pass it to a function
that should return max value in that array. Then pass this returned value to
another function that should return true if that value is a prime number and false
if it is composite.
13. Write a program that inputs a matrix of 4*2. Pass it to a function that should
return the sum of all elements of that matrix.
14. Write a program that inputs no of rows and columns from user. Declare a 2D
array having same rows and columns as user described and input values. Perform
this process again for another matrix. If the order of both matrices is same then
pass these matrices to a function that will perform addition of two matrices and
store their result in 3rd matrix and return this matrix. In main function, you should
store this returning array to another 2D array. Finally pass this resultant (sum)
array to a function that should print all the elements of that matrix.

Best of Luck

Potrebbero piacerti anche