0% found this document useful (0 votes)
74 views

Exercises For Exam 2: Carlos Alberto Hinojosa Montero

This document contains instructions for 12 exercises for an exam on programming fundamentals. The exercises include writing programs to: swap two numbers without a third variable, find the greatest of 4 numbers, reverse a number, check if a number is even or odd, display the days of the week from user input, compute e^x using a series expansion, check if a number contains a digit, produce a multiplication table, print a checkerboard pattern, print the first 20 Fibonacci numbers and their average, print numbers 1-110 with certain multiples replaced with words, and find the maximum and minimum of 3 numbers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views

Exercises For Exam 2: Carlos Alberto Hinojosa Montero

This document contains instructions for 12 exercises for an exam on programming fundamentals. The exercises include writing programs to: swap two numbers without a third variable, find the greatest of 4 numbers, reverse a number, check if a number is even or odd, display the days of the week from user input, compute e^x using a series expansion, check if a number contains a digit, produce a multiplication table, print a checkerboard pattern, print the first 20 Fibonacci numbers and their average, print numbers 1-110 with certain multiples replaced with words, and find the maximum and minimum of 3 numbers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

U NIVERSIDAD I NDUSTRIAL DE S ANTANDER , E SCUELA DE I NGENIERÍA E LÉCTRICA ,

E LECTRÓNICA Y DE T ELECOMUNICACIONES .

Exercises for Exam 2

Carlos Alberto Hinojosa Montero


July 24, 2016

Exercise 1: Write a program to show swap of two numbers without using a third variable.
Exercise 2: Write a program to find greatest in 4 numbers.
Exercise 3: Write a program to reverse a given number (integer).
Exercise 4: Write a program to find whether given number is even or odd.
Exercise 5: Write a program that display monday to sunday. Your program must read a char-
acter and print Monday if the user enters m, Tuesday for t, Wednesday for w, Thursday for h,
and so on.
Exercise 6: Write a program to compute e x using the following series expansion. The user
enters a number (x) and the terms of the serie (n).

x x2 x3 x4
ex = 1 + + + + +···
1! 2! 3! 4!
Exercise 7: Write a program which takes an 4 digits int as input and returns 1 (true) if the
number contains the digit 8 (e.g., 1822, 8018) and 0(false) otherwise.
Exercise 8: Write a program to produce the multiplication table of 1 to 9 as shown using two
nested for-loops.
output
* | 1 2 3 4 5 6 7 8 9
-------------------------------
1 | 1 2 3 4 5 6 7 8 9
2 | 2 4 6 8 10 12 14 16 18
3 | 3 6 9 12 15 18 21 24 27
4 | 4 8 12 16 20 24 28 32 36
5 | 5 10 15 20 25 30 35 40 45
6 | 6 12 18 24 30 36 42 48 54
7 | 7 14 21 28 35 42 49 56 63

1
8 | 8 16 24 32 40 48 56 64 72
9 | 9 18 27 36 45 54 63 72 81

Exercise 9: Write a program that displays the following n × n (n = 7) checkerboard pattern


using two nested for-loops.
output

#######
#######
#######
#######
#######
#######
#######

Exercise 10: Write a program called Fibonacci to display the first 20 Fibonacci numbers F (n),
where F (n) = F (n − 1) + F (n − 2) and F (1) = F (2) = 1. Also compute their average. The output
shall look like:
output:

The first 20 Fibonacci numbers are :


1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765
The average is 885.5

Exercise 11: Write a program which prints the numbers 1 to 110, 11 numbers per line. The
program shall print “Coza” in place of the numbers which are multiples of 3, “Loza” for multi-
ples of 5, “Woza” for multiples of 7, “CozaLoza” for multiples of 3 and 5, and so on. The output
shall look like:
output:

1 2 Coza 4 Loza Coza Woza 8 Coza Loza 11


Coza 13 Woza CozaLoza 16 17 Coza 19 Loza CozaWoza 22
23 Coza Loza 26 Coza Woza 29 CozaLoza 31 32 Coza
......

Exercise 12: Write a program to find the maximum and minimum of 3 numbers.

You might also like