Functions III-Introduction to Computer Programming-Assignment, Exercises of Computer Engineering and Programming

This assignment was given by Dr. Jyoti Lokesh at Biju Patnaik University of Technology, Rourkela for Computer Programming course. It includes: User, Friendly, Menu, Program, Logical, Boolean, Valued, Function, Inputs, Output

Typology: Exercises

2011/2012

Uploaded on 07/13/2012

ekvir
ekvir 🇮🇳

4

(1)

35 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Assignment
Deadline: 30-12-11 section 04
31-12-11 section 8
Write a program containing all of the following functions. Design a user
friendly menu and proper messages for your program. [20 marks]
Question 1
Write a logical (i.e. Boolean) valued function which takes a single integer parameter, and returns
"True" if and only if the integer is a prime number between 1 and 1000 (note that 1 is not usually
counted as a prime number). Test your function by calling it from an appropriate "driver"
program with different inputs.
Hints: (i) if a number is not prime, it has at least one prime factor less than or equal to its
square root, (ii) (32 x 32) = 1024 and 1024 > 1000.
Question 2
Write a function "print_pyramid(...)" which takes a single integer argument "height" and
displays a "pyramid" of this height made up of of "*" characters on the screen. Test the function
with a simple "driver" program, which should be able to reproduce the following example
output:
This program prints a 'pyramid' shape of
a specified height on the screen.
how high would you like the pyramid?: 37
Pick another height (must be between 1 and 30): 6
Question 3
5) Write a program containing a function which prints a table listing the number of occurrences
of the lower-case characters 'a' to 'z' in a char array of length 50
CHARACTER OCCURRENCES
a 38
b 5
c 35
d 7
e 58
f 8
g 8
docsity.com
pf2

Partial preview of the text

Download Functions III-Introduction to Computer Programming-Assignment and more Exercises Computer Engineering and Programming in PDF only on Docsity!

Assignment

Deadline: 30-12-11 section 04

31-12-11 section 8

Write a program containing all of the following functions. Design a user

friendly menu and proper messages for your program. [20 marks]

Question 1

Write a logical (i.e. Boolean) valued function which takes a single integer parameter, and returns

"True" if and only if the integer is a prime number between 1 and 1000 (note that 1 is not usually

counted as a prime number). Test your function by calling it from an appropriate "driver"

program with different inputs.

Hints: (i) if a number is not prime, it has at least one prime factor less than or equal to its

square root, (ii) (32 x 32) = 1024 and 1024 > 1000.

Question 2

Write a function "print_pyramid(...)" which takes a single integer argument "height" and

displays a "pyramid" of this height made up of of "*" characters on the screen. Test the function

with a simple "driver" program, which should be able to reproduce the following example

output:

This program prints a 'pyramid' shape of a specified height on the screen. how high would you like the pyramid?: 37 Pick another height (must be between 1 and 30): 6

Question 3

5) Write a program containing a function which prints a table listing the number of occurrences

of the lower-case characters 'a' to 'z' in a char array of length 50

CHARACTER OCCURRENCES

a 38 b 5 c 35 d 7 e 58 f 8 g 8

docsity.com

The Fibonacci sequence a(1), a(2), a(3), ..., a(n), ... is defined by

This generates the sequence 1, 1, 2, 3, 5, 8, 13, 21, ... Write a function of binary search that searches a specific element in an array of length 10.

 - h - i - j - k - l - m - n - o - p - q - r - s - t - u - v - w - x - y - z 
  • Question
    •  a(1) =
    •  a(2) =
    •  a(n) = a(n-1) + a(n-2) , for all n >
  • its positive integer argument, so that, for example, fibonacci(7) = Write a C++ function "fibonacci(...)" that computes the Fibonacci number corresponding to
  • Question