CS 115 Lab 3 Solved

39.99 $

Description

5/5 - (1 vote)

Lab Guide 03A

Lab Objectives: Functions

1.

a) Write a function called divisible to determine whether a number M is a multiple of another number N. If it is multiple, it will return True else False.

b) Write a script to input a set of positive integer number pairs and then find the percentage of the first numbers that are divisible by the second numbers in each pair. The program will stop if either of the numbers in the pair is not positive.

Sample run :

Enter first positive integer in pair(a number <=0 will stop the program): 6
Enter second positive integer in pair(a number <=0 will stop the program): 2
Enter first positive integer in pair(a number <=0 will stop the program): 5

Enter second positive integer in pair(a number <=0 will stop the program): 3
Enter first positive integer in pair(a number <=0 will stop the program): 4
Enter second positive integer in pair(a number <=0 will stop the program): 9

Enter first positive integer in pair(a number <=0 will stop the program): 0
Enter second positive integer in pair(a number <=0 will stop the program): 5
33.33 of the pairs are divisible by each other

2.
a) Write a function called findDigits which receives an integer number (can have any number of digits) and returns the first and last digits of the number.

b) Write a script to input a set of integer numbers and display those numbers which have the same digit in the first and last positions The program will stop inputting when a number is not a positive number.

Sample run :

Enter an integer number (<=0 will stop the program): 159
Enter an integer number (<=0 will stop the program): 2572
2572 has the same first digit and last digit

Enter an integer number (<=0 will stop the program): 6
6 has the same first digit and last digit

Enter an integer number (<=0 will stop the program): 0
0 has the same first digit and last digit

Enter an integer number (<=0 will stop the program): -1

  • Lab3-0uyznv.zip